views:

72

answers:

2

Hello All,

My Application is crashing due to low memory [ Received memory warning level 1 + 2]

To trace this I have used Instrument and come with following points

Test Enviorment : Single view controller added on Window

  1. When I don't use UIImageView Real Memory is used 3.66 MB

  2. When I uses UIImageView with Image having size 25 KB : Real Memory is used 4.24 MB. almost 560 KB extra when compare to w/o UIImageView and which keep on adding as I am adding more UIImageview on the view.

below is sample code for adding UIImageview which I am refering

UIImageView* iSplashImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Landscape.png"]];
iSplashImage.frame = CGRectMake(0, 0, 320, 480);
[self.window addSubview:iSplashImage];

AND

dealloc

if(iSplashImage)
{
  [iSplashImage release];
  iSplashImage = nil;
}

Issue is this 560 KB is not getting release and after some time application receives low memory warning.

Can anyone point out if I am missing something or doing else. As My application uses lots of Images in One session.

Thanks in Advance,

Sagar

A: 

Are you calling [iSplashImage removeFromSuperview] or smth like this? Image needs more memory than the file, since it is unpacked in memory- 320x480x4 = 600Kb

Nickolay O.
Thanks Nickolay for reply. right now I am not calling [iSplashImage removeFromSuperview], does it causing memory leak?about the calculation 320*480*4 is it like [ horrizontal * vertical * file size ] ?
Sagar Mane
A: 
if(iSplashImage)
{
  [iSplashImage release];
  iSplashImage = nil;
}

Not your question, but I'm pretty sure that [iSplashimage release]; does all of this in one line. if iSpashImage = nil the message will evaluate to a non-proc. iSplashImage at that point is just a pointer, so whether it is nil or not doesn't have memory impact.

fogelbaby
You are right Fogel. the purpose behind this is "When we will try to access iSplashImage ( after deleting ref might contain some garbage info)which is not initialized we can add the case likeif(iSplashImage){ // Do with iSplashImage} it will avoid unnecessary crash.
Sagar Mane