Can anybody tell if there are any tools other than CLANG static analyzer and the Memory Leak tools available in XCode.I am developing an application and it crashes after 10 mins of usage due to low memory.I have solved all the leaks pointed out by CLANG and the Tools of Xcode,but still not able to solve the low memory issue.
Thanks
Your application might not be leaking memory. Low memory warnings can also be caused by an application retaining too much memory. If you application is continually consuming memory, it could be that you are retaining references to objects when you shouldn't be. Trying running inside of Instruments and monitor Memory Allocations.
If the problem is that many objects are accumulating in memory, you need to modify your program so that this is not necessary. If they are downloaded, try saving to a file or files. Then you can re-load the objects into memory only when absolutely necessary. The iPhone has a fairly low memory threshold, so applications should be designed with this in mind. How much memory is being consumed? What objects are taking up all the space?
Related
From using the Allocations instrument to track my app's memory usage I've noticed that throughout the runtime of the app the memory usage keeps going up. Looking through the heapshots I can see that the largest chunks of memory are being allocated by a method called CJPEGCreateImageDataWithData in the library GMM. I can't find anything online about this happening, but it certainly looks like this is responsible for my app's memory-hogging. Here's a screenshot of the pertinent part of the Allocations output:
What might be the reason for this, and how would I avoid it?
The simulator and the device use a different amount of memory due to several factors.
MKMapView should behave well enough on iOS 4.2 or higher. Even when you see a steep memory increase, note that it is cache memory, and all that is not required by MKMapView to work. The only problem is that it may bring your application closer to a low memory warning. You can emulate this warning and see if your app survives. Other than that, you can't control the map cache directly. If you don't have enough memory for your app to work, try using the normal map instead the satellite one.
If my app uses less than 10MB do I have to bother to use those methods? I know that they are for caching low memory situations but this might occur only if you do not tested you app before releasing it. If you have tested your app, the app does not have leaks, have a small memory footprint, then why should anyone bother to use memory warning methods?
Your app is probably not the only thing running on the device. Other apps and processes are also taking up memory, and in some situations they may need it more than you. It's always a good idea to respond to memory warnings by releasing cached data that can easily be loaded again. That way the operating system has control over the memory usage, and it won't have to terminate your app.
My app uses about 50 MB of memory at startup when I look at dirty memory using the VM Tracker instrument. It's a pretty simple app, and from what I recall at WWDC this year, this seems like way too much memory use for an app with only one simple UIWebview at startup.
I think I recall someone from Apple telling me to keep my memory use below 20MB as a guideline.
Before I go off and try to track this down - what's a good target to keep performance smooth and mem warnings reasonable?
Virtual Memory != RSIZE. Don't get confused. Virtual Memory includes all sorts of shared memory, including mapped files and frameworks. What you really care about keeping low is your resident memory (RSIZE).
i have an application which takes "live bytes" up to 3mb. The application showing memory warnings and it will crash continously. when i use object allocation tool i can see the live bytes.im using imageWithContentsOfFile in many places. i can see NSConcreteData object is taking more momory.what is the reson for that? may i know how much memory is allowed to an application.
You can't really know how much memory you're allowed to use, but in general you're fine up to 20mb on iPhone/iPod devices. However, your app can be killed not only for using too much memory, but for failing to decrease memory usage when warnings are issued. So even if you're not using all that much memory, if the system detects that you don't release any memory when getting memory warnings, your app might be shut down. At least that's my experience, maybe others have more detailed knowledge about what's going on.
imageWithContentsOfFile: has a built-in caching mechanism, so if you're loading the same images over and over, there should be very little overhead.
EDIT: imageWithContentsOfFile: does not cache images. The method imageNames: does cache images, and it's the only image creation method that does.
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.