views:

69

answers:

2

Hi,

is it possible, that when the iPad application is forcibly closed/killed by the iOS becuase of 'out of memory situation', the memory the application allocated is not 100% released? I think that the memory allocated directly by the client is released - there is even HW support for this, but we were observing that if the application is closed/killed by iOS and consequently started again less and less memory is available, until the iPad must be restarted. We think that some memory are allocated e.g. by background running daemons, which do some job on behalf of application and if the inter-process communication is not successfully finished, used memory on the daemon side might not be released properly...

Is something like this possible? BR STeN

A: 

If you alloc memory it will stay in the heap until you release it, even if the app that did the alloc is long gone. Like you have seen restarting the device will clear the heap.

You should always manage memory events, there is a method for this.

- (void)didReceiveMemoryWarning;

typically you would release everything you can, especially if its a level 2, as if you don't your app is going to close anyway.

However, When your app exits it should be calling dealloc anyway! so you may have a general leak.

Luke Mcneice
Hi, are you really sure about the fact, that if the process is killed by OS or closed by user, the memory it allocates during its lifetime is not released automatically? This sounds strange, I do not know OS, which is acting like this...
STeN
Im not a guru on this, but even if you write a C++/c program in windows and do an malloc without a free, this happens too. High level languages are different as they have good garbage collections, or run apps in VM's and therefore can just kill the VM's memory when the app closes but C, obj-c and c++ are not like this.
Luke Mcneice
Additionally if an object has been allocated then set to nil before a release your in big trouble.
Luke Mcneice
Hi, normally the process is assigned a portion of memory it owns during its life time. It is all released when the process dies, so it is not possible to create leaks if the process crashes. There are of course some exceptions, like shared buffers, but normal memory allocated with mallocs or related functions should be freed. That's how normal OS like Linux or Symbian behaves. I think this applies also on iOS, isn't it??? It will be strange if a modern OS behaves differently those days...
STeN
Dynamically allocated memory exists until it is released either explicitly by the programmer, or by the garbage collector. GCC does support garbage collection though i thought it was off by default.
Luke Mcneice
A: 

I'm fairly certain that the method:

- (void)applicationWillTerminate:(UIApplication *)application;

will run even if the app is crashing. This would be a good time to ensure that everything is released, if it is not getting caught by the memoryWarning.

Kyle
Hi, I am convinced, that a good application should release everything when being closed, but when the OS calls the applicationWillTerminate and application is terminated in next step I hope the memory is anyway released by operating system itself - at least this is on Linux, Symbian, Windows done. I guess this method is rather for other purposes, like e.g closing files, etc. BR
STeN
No iOS has no way to release the memory unless you specifically handle it. All objects must be released if retained or autoreleased. If your app crashes with objects on the heap, they stay in memory until the device is restarted.
Kyle
Hi, I ma talking ONLY about situations in which process is killed/crashed (see my comment above)!! Then normal memory allocated with mallocs(C)/new(C++)/alloc(Obj-C) or related functions should be freed. Hope the same is on iOS and I am almost sure it does! BR STeN
STeN
iOS will not release memory on it's own in any situation.
Kyle