Memory Warning Level Indicator - iPhone SDK - iphone

I am using a ton of timers that update images in my game, and whenever I run it, the debugger somehow gives me a memory warning indicator level. I try adding some timers through a background thread, but that made a very small difference. Is there anyway I can reduce the memory usage of my app without having to get rid of my timers?
Thanks,
Kevin

In XCode, select from the menus: Run -> Run with Performance Tool -> Leaks. This will open an app called Instruments that will help you find the problem. See the Instruments documentation for more details.

Related

new in using XCode Instruments to interpret memory warning for iPhone development, guidance needed

I am working on an iPhone game which receives memory warning that I am not experienced enough to interpret. I have been watching some iTunesU tutorial but I am still not very good at this..
I have received various memory leaks whilst running my game and I wanted to understand how to interpret the stack trace show in Instruments properly.
I attach a screenshot of the ObjectAllocation instrument output . Even when I zoom filter I don't manage to filter the data in the ObjectSummary .
The peaks in memory usage in 1 happen when the GameScene is initialized and all the data is loaded (ParallaxBackground, CCSpriteBatchNode) and Sprites and bullets frames are created (in an CCArray of spriteFrames).
The big blue peak is just at load time but the app freezes and then crashes only after a while and from the graph I see that the memory usage (blue bar) has gone down.. so I don't quiet get that. Also, whenver I try to use the leaks instrument the App crashes..
I know is a very silly question for someone experienced, but I just need some extra help getting started with this toolset.
I think the memory problem are due to the sprites I allocate in sprite cache classes, but I am not sure on this and hence wanted to investigate this using Instruments but can't find out how to see what is the object causing the memory warning and how to access the stack trace..
PS: I am running on an iPod 4th generatio and I am using Cocos2D as library
EDIT: I do not also understand why if the Live Bytes are only 1.01 MB the App crashes and why I still receive a memory warning (see black flags). Is it due to some pointer referencing to some null variable or due to an excessive memory allocation? 1.01 MB doesn't seem much to me..
EDIT 2: Following Marion's advice I used the Activity Monitor and realized that the effective real memory usage is 55.39 MB. I misinterpreted the "live bytes" word. I will try to dig into this further and will leave the question as unaccepted for now to allow other people contribute. If I won't have any other answer within one-two days I'll mark as accepted the current answer. Thanks!
Thanks a lot!
If you want to find leaks, use Leaks instrument instead of Allocations. To find out, how much memory use at the moment, use ActivityMonitor.
If you will have problems with memory in cocos2d, you can try to purge cache. In cocos2d you can purge CCTextureCache, CCSpriteFrameCache, CCAnimationCache. It will release unused textures and frames.
If you want to check if all of unnessesary textures were removed from memory, you can place breakpoint to CCTextureCache class and call, for example, sharedTextureCache and look throw the content of textures_ dictionary. Or add some method to this class to be able to dump current state of cache.

IPhone app Memory Issue

I check my Iphone App in Instruments and it's using 392.00kb of memory which does not decrease and keeps on increasing.
So although I am not using a UITableView there is an entry for [UISectionRowData refreshWithSection:tableView:tableViewRowData:].
Try using HeapShot, see this tutorial by bbum.
Basically in the Allocations instrument click Heapshot, run an iteration of your app, repeat 3 or four times and look for items that are persisting.
Another quick check is Analyze. Just run Analyze and it may find places where you are not handling memory correctly.

Stuck in memory leaks in my project

I am using UIImage picker, Local notification, event calendar, Date Picker , Facebook Sharing, Sounds, Navigation controller , database . My application is crash after some time, the reason is not same, Some times memory is full and some times too manny other receive memory warning. Please guide me how can i generally remove the leaks?
Have a look at this Cocoa Tutorial: Fixing Memory Leaks With Instruments. Instruments is the way to go to find leaks.
More resources:
Finding iPhone Memory Leaks: A “Leaks” Tool Tutorial
Apple's official Memory Usage Performance Guidelines / Finding Memory Leaks
Use Intstruments with the Leaks profile... see this article Leaks!
1.first of all release the objects in the dealloc .
2.Go to the xcode there in mainmenu you find the build tab.In that pressed on the build and analyze .It gives the errors.Remove those warnings.
If you are using autorelease objects, make sure it gets released at the right time. If you can,try not to use Interface Builder, i feel something is fishy abt it when it comes to memory.
Check the NSString objects, they can have devastating effects if not released on time.
also remember [UIImage imageNamed#"abc.png"] caches the images which also causes running low memory warnings.
Try to create your view hierarchy programmatically.

memory leak - application exited with signal 9 in iphone application

I have an application which is utilizing a lot of memory by using UIImageView, creating graphics context, calling web service, drawing using quartz2d, blending images, playing video, recording and so on. But now the application is exiting after some time with a memory warning.
Is there any way to clear the ram usage like clear cache or something like that.
First of all delete build folder from your directory,then clean all targets,then go to menu Build
then Build and Analyze and solve the potential leaks.
After doing this you should run your application through instruments and see where memory leak occures
and then try to solve it.
You, can do one thing, put your application on leaks analyzer, and check out the leaks, and prior you go through your code and release, the allocated objects after those use have finished, by releasing them.
Here is a good tutorial. http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/

How do you detect memory leaks on iPhone?

I'm using the Leaks Instruments feature through Xcode to (try and) find memory leaks. I still haven't figured out how to use this program. I click Leaks in the program and see memory increasing as I do various things in the simulator. I have Extended Detail pane displayed. The only thing in Extended Detail pane that references my app is main. As in the main method produced by Xcode. Everything else is UIKit, Foundations, and other SDK classes I didn't write. What am I doing wrong that nothing is showing up from my app?
Before I hit 3 minutes, there are over 100 leaks totaling 2.5k. Is this common?
I've written up a Tutorial on using Instruments to track iPhone memory leaks. I'm not sure if it will help you with what you're dealing with or not...couldn't hurt, though. :-)
http://www.streamingcolour.com/blog/tutorials/tracking-iphone-memory-leaks/
Change the view to "Extended Detail" on the instruments panel. This will show you the stack trace of each leaked object after you stop recording and select the leaked object.
You do see calls into the API, but what you are interested in is finding the last method of your application before the API calls, that is where the leak is.
A tip: turn on "gather memory contents" in the leaks view. Seeing the object values should also help finding where the problem is.
You don't want any leaks. 100 leaks is not typical (at least in my apps ;) Typical should be 0.
I'm not familiar with how to use Leaks, but you can always try running the Clang analyzer on your code to see if that'll turn anything up: http://clang.llvm.org/StaticAnalysis.html. It can often find many bugs that might lead to memory leaks.
Xcode: run -> Start with Performance Tool -> Leaks
Keep in mind that the Simulator may leak when the device will not. Ran into that once already with UITableViewController class.
Use LLVM/Clang Static Analyzer.
Note also that the leak tool is not going to show you instances where objects are over-retained and still held on to. Leaks are cases where objects that should have been let go are just hanging around with no-one to clean them up. Over retained objects are validly held onto even though you'd think they should be gone - thus the leak tool cannot point them out, since they are still referred to and there's no way to tell them apart from objects that should still be retained.
To find those, use the memory reporting tool and make sure that memory use goes down fully after you free an object. If you notice something isn't freeing memory, you can start by putting breakpoints in dealloc to see if what you expect to see released is actually getting released.
You need to look for both cases to keep a clean memory footprint.
Run -> Start with Performance Tool -> Leaks
To detect memory leaks you can use the "build and analyze" function of Xcode.
Simply select Build -> Build and Analyze in the Xcode menu.
Made a sum up of the main memory leak tools: http://bcaccinolo.wordpress.com/2010/09/15/iphone-essential-performance-tools-list/
Leaks application that can be found in Xcode: run -> Start with Performance Tool -> Leaks.
Apple’s Instruments utility that can be found in /Developer/Applications/Performance Tools.
One of the best way to find the memory leaks is Select Product-> Analyze. In the left Xcode shows in which file you have memory leaks. What are the variable causing memory leaks. This is one of the best way to find memory leaks.
The memory debugger (button just over the console, next to the view debugger) is quite useful too.
It will show you leaks, and you can check /filter easily if objects are still in memory when they shouldn't.