在 iPad 上跟踪 EXC_BAD_ACCESS
我一直在使用这段代码来创建我的 UIWindow
UIMyWindow* win = [[UIMyWindow alloc]
initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIMyWindow 没有什么特别的,它只是有一个指向 C++ 类的指针,该类对 ObjectiveC 进行了一些包装。
最近,我的应用程序在添加了一些不必对错误执行任何操作的代码后开始崩溃。我添加的代码行只是分配一个 C++ 对象,但程序执行从未到达这一行。
有趣的是,我的代码可以在发布版中运行。
我唯一的猜测是我在一个完全不同的地方造成了一些内存损坏。我的问题是: 这可能是什么类型的内存损坏? 是否有一些好的做法可以追踪它们?
I've been using this code to create my UIWindow
UIMyWindow* win = [[UIMyWindow alloc]
initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIMyWindow isn't anything special it just has a pointer to a C++ class that does some wrapping of ObjectiveC.
Recently my application start crashing after adding some line of code that doesn't have to do anything with the error. The line of code that I added is just allocating a C++ object but the program execution never reaches this line.
Interesting enough my code works in Release.
My only guess is that I made some memory corruption on a completely different place. My questions are:
What type of memory corruption that can be?
And is there some good practices to track them down?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您肯定有一条消息发送到已释放的对象。
您应该尝试使用 Instruments.app 调试您的程序。它应该向您显示潜在的内存问题。
另请查看 NSZombieEnabled 环境变量。基本上,它会在释放对象的位置留下一个虚拟对象。当消息发送到该虚拟对象时,您会收到警报,以便您查看问题所在。
You certainly have a message that is send to a deallocated object.
You should try to debug your program with Instruments.app. It should show you the potential memory problems.
Also take a look at the NSZombieEnabled environment variable. Basically, it leaves a dummy object at the place of the deallocated object. You'll be alerted when a message is send to that dummy object, allowing you to see where the problem is located.