When, I run my application in the simulator using the Leaks instrument, it uses about 2.5mb of memory. When I run it on the iPhone, it takes forever to launch, slowly climbs to ~34mb of memory and then crashes. However, when I run it on the iPhone without Leaks, it launches quickly and runs fine. Why is this?
Do you have zombie detection enabled?
Zombie detection will cause every object allocated to never be deallocated (the object is marked as a zombie on deallocation). This will cause memory growth as you describe. A common mistake is to leave zombie detection enabled when using Instruments, either through environment variables or through the checkbox in the Object Alloc instrument.
If it isn't zombies or leaks, then it is -- as others have said -- memory being allocated and sticking around. Use the Object Alloc instrument to track the objects allocated in your application and make sure that every single one of them exists for a reason. You can turn on "only track live allocations" to filter out all the objects that have already been deallocated.
The crashes are probably due to the memory leaks you have in your app and the device running out of memory. Without seeing any code it is impossible to tell. Here is a tutorial on how to use instruments
The "takes forever to launch" and and runs slowly is due to the leaks monitoring system polling the device every 10 seconds for information
EDIT: It is probably due to keeping too many objects alive in memory at a given time. Check instruments and Object Allocations. Just because you have no leaks doesnt mean you can't run out of memory
Related
I'm in the process of ironing out a few memory allocation issues in my iPad app and have spent a long while watching CFString grow and grow and grow (as a still living object) under the zombies instrument, it wasn't until I switched to the Leaks or allocations instrument that I noticed it doesn't grow much at all (created and still living remains stable throughout) can anyone explain why this is happening in zombies but not leaks or allocations instrument, its making me wonder if CFString is an issue or just a false positive thrown up by zombies ....
Zombies specifically doesn't release memory so that you can see if you are accessing memory after you release it. You can't try to detect leaks while using zombies.
Under the Zombies instrument, you should just be trying to detect zombies. The rest of the behavior of your application isn't necessarily going to be the same. To maximize the chance that you detect accessing a zombie, non-standard allocators might be used.
If an application produces a lot of memory leaks, are they "just" an in-app problem or are they also in RAM after the termination of the application? So does the iPhone OS release the memory allocated for the sandboxed application?
Thank you
Memory leaks are blocks of memory allocated by the OS for your program to use while it is running, but not correctly returned as not in use when the program has finished with them. So this memory is 'lost'. Your program isn't using it, but the system doesn't yet know that it is free for other use.
When your application finishes running, all of the memory allocated to it by the OS, will be returned for re-use. Which answers your question.
However, memory leaks are a significant bug. On a low-memory device, like an iPhone, the less memory you consume the better, you don't want to be leaking memory as you run. If the device runs low on memory, your application may be terminated or crash, unexpectedly.
Memory leaks occur when you allocate any object and miss out to release that objects while running application , so do analyse in xcode which will help in checking memory leaks, and run profile mode in xcode will help to check leaks possible in application.
and use NSAutoReleasePool to release the autorelease objects which will be created when you just assign objects wothout allocating
hope it helps .
Memory leaks are an in-app problem, but can have side effects on the total available RAM.
They are blocks of memory that are marked in use when they actually are no more used. So they are lost to the app. If you have leaks, this will increase memory consuption. And bad memory usage will be noted by the system and the app might be jettisoned (killed) by the watchdog, jetsam.
So keep your memory leaks to a minimum ;-)
It has an effect on the overall OS, but negligible in consequences. Because your app is not killed when you tap the hole button, but rather "backgrounded", all the memory that's used by your app is still live and unavalaible to the system. Jetsam will first tell you that the memory is low and ask you to get rid of stuff you don't need. Of course you cannot free your leaks.
If you still use too much memory for the system, and it needs to allocate more memory for another process, your app will get killed. All the memory it used will be freed, leaks included.
Leaks are bad, use the static CLang analyzer in Build and analyze.
I am wondering is there a way to find out memory allocations that dont get deallocated on iphone application exit or it's termination .
I have been using instruments fixed most of leaks that I had in my application, but i am worried that there are still some allocation that i didnt release.
Thanks
In short, don't bother trying to find and fix leaks caused during application termination. It is quite likely -- almost guaranteed -- that neither Cocoa nor the iPhone frameworks try to release all memory on termination as doing so is entirely a waste of CPU cycles.
If you are going to hunt down leaks, do so through using your application as your users do, keeping an eye on the Object Alloc instrument's analysis.
What can be useful, though, is putting a hook in that is triggered before termination is an absolute. Stop there and make sure the app's object graph is as expected.
No need to worry about cleaning up memory on application exit. The operating system will wipe out any memory allocated to your application at that point.
but if you use opengl please clear out your buffers :P.
After running with the memory analyzer, my app seems to increase its memory consumption very slowly.
The analyzer did detect memory leaks whenever certain events occur, which i quickly fixed. But this slow consumption of memory is occuring when im not doing anything in the app. The app basically just starts. Consumption is more noticeable when I touch an object and move it about.
Is there an undetectable leak in my app or is this normal behavior (perhaps of internal framework libraries)?
Thanks
The Leaks tool detects programming errors (object going out of scope without being freed) but cannot detect semantic errors. A common error of this type is to hold on to something after you're finished with it in an array or in a global variable. One iPhone-specific cause I've seen is to keep pushing views into a UINavigationController without cleaning up the ones you aren't going to use anymore.
some times memory analtzer also not able to track leaks in our application . Best way is that when your memory consumption is increase , in that controller check wether all objects are properly released or not.
I'm reading up on the leak-finding tools for iPhone development and intentionally inserting and looking for memory leaks in my small program before I get into a bigger, harder-to-debug project.
It's no problem to identify a memory leak that, say, occurs in a regularly invoked method like responding to a touch event. The leak instrument will eventually identify virtual memory that is unclaimed.
I'm more worried about a leak in code for exiting the entire system. Once I completely exit my app, is it a concern that something wasn't deallocated, or does iphone OS automatically reclaim all user mem at that point?
This issue is unclear to me after reading quite a bit of documentation, and without knowing anything else, I assume it must work like other OS's in that regard and just take back all user space. If that's so, won't I be fine cleaning up regular leaks so my app can run for any amount of time with bounded memory, then not worry so much that everything gets freed up at exit?
Also, if it is critical to free everything before exiting because it will not be reclaimed by the OS, is there a good way to keep my app alive in the instruments after exit for inspection? When I press the home button in the simulator or on the device haven't I already lost the chance to detect exit-time leaks?
Yes, ending your program will release every bit of memory held by it. Anything otherwise is an OS bug, and you're unlikely to find that occurring.
EDIT: I bet your asking this because documentation says "iPhone doesn't support garbage collection." That statement, however, doesn't apply to freeing memory when a program ends. It's only talking about how you have to handle freeing your own memory while your program is running.
The iPhone should be using virtual memory, so (theoretically anyways) the OS will clean everything up when a leaky app exits.