开发者

Memory leak in UIImagePicker in iphone

In my app user can 开发者_如何学Pythontake as may picture from camera, so after three time taking the picture it crashed. I can't resize the image (its requirement). So is there any other way to avoid memory leak.

Thanks


There is a know issue with the uiimagepickercontroller with memory leaks.

Apple recommend that you only allocate and instantiate only one instance and store it somewhere for the life of the application (whilst running that is).

Don't create a new one, use it and deallocate it each time you want to use the control. If you do, your memory usage will keep increasing until it crashes your app.

Personally I store it as a property in the appDelegate, but there may be a better way of doing it.


Edited: Thanks to CharlieMezak. Yes, such a leak might cause a crash. You'd better do some checking based on CharlieMezak's suggestions.

What may also cause crash is your code trying to access a piece of memory that was deallocated already.

I suggest you first check your code to see if there is any autorelease object that was not taken care of.

Second, turn on NSZombieEnabled, and test your app. If it's indeed trying to access something that was already deallocated (Zombie), the console will show you.

Third, and most importantly, post your crash report and part of the code that might be responsible for such a crash. Your description is somewhat vague, we need to see the report.


It sounds like your app is able to handle the photos correctly (from the user's perspective) two times, but on the third time it crashes. Sounds to me like a memory leak.

If it were a logical error in the code, or an attempt to access a deallocated object, the crash would probably occur the first time you take a photo.

It sounds like you're leaving the images in memory, so by the time you take your third photo, you're out of memory because the first two are still sitting there. Make sure you're releasing what you retain, and if you continue to have trouble, post your code!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜