Memory management issue

HI,
I have finished my first ios game for children using cocos2d-x 3.0, but there is still a memory management issue (received memory warnings, sometimes the app crashed).
I think that i have this issue because i have used many long mp3 sounds.

I would like to know if there are best practices to manage huge amounts of sounds in an app, which allow me to minimize the memory consumption.

Thank you for your time and consideration.

are you pre-loading these sounds before you use them?

How long are the MP3’s?

Did you check for memory leaks? (that means properly understanding both the retain/release behavior and the C++ way of memory management)

Did you ensure only the textures you need are loaded when you receive memory warnings?

What did you learn running Instruments?

No,i didn’t , because they take long time to preload. the max long of a sound is about 1 min and i used 50 sounds, i play 1 sound in each page of a pageview(cocos2d::ui::PageView).

I used cocos2d-x classes, with the static method Create, which handle the retain/release automatically (i think). and i don’t know how to chek for the memory leaks.

About your sound, let’s calculate the memory size of each sound. There are 60 sec long, let’s assume stereo, with 4 bytes per sample and 44khz (that’s an upper range).
Each sound is at max: 60 x 2 x 4 x 44000 = 21120000 bytes, so about 2MB.
If you have 50 sounds and load all of them at the same time, at 100MB, you are going to have a problem, so as @slackmoehrle suggested, be sure to check your sounds are properly unloaded when not needed anymore.

To check for memory leaks, there are two ways of doing that:

  • by running some software that check memory usage, then see if your memory usage keeps increasing over time when it should be stable (some software will also try to see memory leaks, but that’s not always 100% exact). Which device are you testing on? As @corytrese suggested, Instruments is the go-to software for Mac and iOS.
  • by doing a code review to check for anomaly:
  1. Each retain should have a corresponding release or autorelease somewhere
  2. Each new should have either a delete (if it’s not a Ref subclass) or a release (if it’s a Ref subclass)
  3. Each malloc should have a corresponding free
  4. Each time you add an object to a Cocos data structure, you should have a corresponding remove (because Cocos data structure retain objects passed to them)

When you use a create, you don’t need anything, since the object is autoreleased during the create (create = new + autorelease).

Thanks, also i preloaded all my images in the splash Screen(about 80 MB). is this good?

80MB seems an awful lot. Do you really need that much? Do you have lower resolution images for lower resolution devices? What devices are you targeting (if you only target recent ones, that may be fine)?
Here is a relevant StackOverflow post about maximum memory budget: http://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget

Also, are those 80MB calculated with a compressed format (png, jpg …) or uncompressed? Don’t forget images
loaded in memory are uncompressed, because it’s required for fast rendering.

Yes i need that much, i have lower resolution images for lower resolution devices with ‘.pvr.ccz’ frormat (i used teturePacker), but 80MB on The run time.

Thank god for Instruments, right? Whew – I never would have gotten a handle on my memory utilization without profiling on hardware.