释放模式下的AccessViolationException(C ++) [英] AccessViolationException in Release mode (C++)

查看:127
本文介绍了释放模式下的AccessViolationException(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Visual C ++以发布模式运行我的应用程序时,遇到以下异常.

I'm getting the following exception when I run my application in Release mode from Visual C++.

未处理的异常: System.AccessViolationException: 尝试读取或写入受保护 记忆.这通常是一个迹象 其他内存已损坏.在 _cexit()at .LanguageSupport._UninitializeDefaultDomain(Void * cookie)位于.LanguageSupport.UninitializeDefaultDomain() 在 .LanguageSupport.DomainUnload(Object 来源,Eve ntArgs参数)位于 .ModuleUninitializer.SingletonDomainUnload(Objec t来源,EventArgs参数)

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at _cexit() at .LanguageSupport._UninitializeDefaultDomain(Void * cookie) at .LanguageSupport.UninitializeDefaultDomain() at .LanguageSupport.DomainUnload(Object source, Eve ntArgs arguments) at .ModuleUninitializer.SingletonDomainUnload(Objec t source, EventArgs arguments)

在调试模式下不会发生这种情况.最初,我在家用计算机上看到了此异常,但在工作计算机上却没有看到.当我继续在工作计算机上进行开发时,最终遇到了麻烦.

This doesn't happen in Debug mode. Initially, I saw this exception on my home computer, but not work computer. When I continued to develop on my work computer, I ended up bumping into it.

此外,我发现当我添加三个const std :: string变量时,将引发异常.如果我删除了,那么一切都会顺利进行.

Also, I found that when I added three const std::string variables the exception was thrown. If I removed then then all went well.

另一条信息:我发现在发布模式下关闭所有编译器优化都会使异常消失

Another piece of information: I've found that turning off all the compiler optimizations in Release mode makes the exception go away

有些可疑的情况正在发生.关于如何进行追踪的任何想法?

Something fishy is going on. Any ideas on how to track this down?

感谢您的帮助, 乔

推荐答案

Joe,您有内存泄漏.

您可能正在尝试使用一些已删除的内存.

You're probably trying to use some memory that has been deleted.

请参阅这篇文章了解内存泄漏的常见原因以及如何识别他们,否则,搜索"C ++内存探查器" +您的编译器/平台,它将提供指向适用于您的编译器和平台的内存探查器的链接,这些链接将通过观察程序在运行时如何使用内存来帮助跟踪内存泄漏

See this article for common causes of memory leaks, and how to identify them, otherwise, search for "C++ memory profiler" + your compiler/platform, it'll give links to Memory profilers suitable for your compiler and platform, these will help track down the memory leak by watching how your program uses memory as it runs.

希望这会有所帮助.

编辑

如何追踪?这是我的头等大事,在其他地方可能会有更好的建议. .

How to track it down? This is off the top of my head, there may be better advice else where . . .

查找代码崩溃的位置,它将在访问某些指针的内容(或删除指针)时出现. 问题在于该指针具有a)从未分配过b)已被删除. 遍历所有对该类型指针的引用,它们是否在复制ctor/赋值运算符中使用?

Find where the code crashes, it'll be when accessing the contents of some pointer (or deleting a pointer). The problem is that that pointer has either a) never been assigned b) is already deleted. Go through all references to pointers of that type, are they used in copy ctors/assignment operators?

如果是,是复制内容还是只是指针? 如果仅仅是指针,那么包含类是否正在尝试删除指针?如果是这样,则第一个死亡的类将成功,第二个死亡将引发访问冲突.

If so, are it's contents being copied or just the pointer? If just the pointer then is the containing class trying to delete the pointer? If so the first class to die will succeed, the second will throw an access violation.

如果您未明确编写复制ctor和operator =的代码,则应隐藏它们(声明私有原型,但不实现它们),这将阻止编译器为您生成默认实现.

If you don't explicitly code copy ctors and operator=, then you should hide them (declare private prototypes but don't implement them), this stops the compiler from generating default implementations for you.

隐藏它们时,在使用它们的任何地方都会出现编译器错误,这可能是您可以清理它们,或者需要为每个类实现副本ctor和operator =.

When you hide them you'll get compiler errors everywhere they're being used, it might be that you can clean these up, or that you need to implement the copy ctor and operator= for each class.

我明天或两周开始放假,如果对此有任何疑问,请立即直接给我发电子邮件(按照我的SO用户页面上的链接).

I'm on vacation from tomorrow or two weeks, email me direct today (follow the link on my SO user page) if you've any questions on this.

这篇关于释放模式下的AccessViolationException(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆