Is there any way for me to detect when I receive Memory Warnings from the OS and free memory accordingly?
I have some large dictionaries that I need to read from. There are 4 of them, I only need to do a lookup on them sporadically, and they eat up a lot of memory, but I can't seem to find a way to load and eject them from memory as needed. This means that I end up needing to always keep all 4 in memory, and if the iPhone has been running for awhile and is using up a fair chunk of its memory, the OS will kill my app because of these dictionaries.
I've tried setting all their references to null right after I use them, but this doesn't seem to free them very quickly, and puts me in trouble if I need to use the same one twice in a row (it gets allocated twice). Do I need to set their references to null and then call for a gc sweep right away? Ideally I'd like to be able to avoid doing this unless I'm receiving memory warnings.
Thanks for any help.
asked Mar 31 '11 at 04:40 AM
One possible way would be to create and store your dictionnaries in xcode and build an interface to it. Within xCode, you'll get likely more accurate control over memory management. There is an example in the [resource section] regards interfacing
I had lots of trouble with this as well, but it was for normal content like gameobjects and textures, I could not free anything properly unless I loaded scenes in a very special way. Look at this answer for reference it might hold some kind of answer useful for to you.
Sorry I can't provide you with a more specific solution to your problem. Hopefully an expert will step in and describe how to properly release stuff for the Garbage Collector to do its work.
: http://unity3d.com/support/resources/example-projects/iphone-examples look for the nativecode example