I am developing an iPad app and found some memory leaks using Instruments and Analyzer. I tried to release some objects which resulted in the crashing of my app.. Are memory leaks allowed in an app? If so, until what extent they 开发者_Go百科are allowed? Is there a way to completely remove the memory leaks with out the app getting crashed??
Generally speaking, it is possible to make sure that the code which you write is leak free. This is not to say that Apple frameworks and internal libraries won't leak at all.
If you call alloc
, new
or copy
make sure to call a corresponding release
or autorelease
. Apps that leak a lot are bound to crash often. Apps that crash often are likely to be rejected from the App Store.
Please read this. We can create an application with 100% leak free. Enable NSZombieEnabled to check why the crash occurs.
It's best to remove as many leaks as you can.
But if there are a few remaining in your application that you can't remove, Apple will still accept your application - as long it doesn't crash frequently.
Just make sure when you alloc
something - it's released with release
or autorelease
.
That's the best way of making sure leaks don't occur.
Leaks are much, much easier to not have in the first place than to try plugging later when the app has memory issues. Fortunately in the iOS/Cocoa world the memory management rules are clear and simple. However as others have said there could be leaks in code you didn't write :(
精彩评论