leak in my custon View

Discussion in 'iOS Programming' started by sujithkrishnan, Aug 10, 2008.

  1. sujithkrishnan macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    Hi all..


    Folowing is a custom View for SPLASH SCREEN what i created....

    In my main Window i am loading this view for busy state..

    But i am getting lmem-leak on the line

    [window addSubView:splashScreenObject];

    Instruments is not showing where in SplashScreen.m the leak is...

    Kindly help me with where i went wrong in following code...

    Code:
    //
    
    #import "SplashScreen.h"
    
    
    @implementation SplashScreen
    
    -(id)initWithImageNamed:(NSString*)imageName backgroundColor:(UIColor*)bgColor
    {
    	if(self  = [super initWithFrame:[UIScreen mainScreen].applicationFrame])
    	{
    		self.backgroundColor = bgColor;
    		UIActivityIndicatorView *actView =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    		[actView startAnimating];
    		actView.center = CGPointMake(130.0,230.0);
    		[self addSubview:actView];
    		[actView release];
    		
    		
    		UIImage *splashImage = [UIImage imageNamed:imageName];
    		UIImageView *splashImageView = [[UIImageView alloc]initWithImage:splashImage];
    		CGPoint splashImageCenterPoint  = CGPointMake([UIScreen mainScreen].applicationFrame.size.width/2.0,
    													  [UIScreen mainScreen].applicationFrame.size.height - [splashImage size].height/2.0);
    		
    		splashImageView.center = splashImageCenterPoint; 
    		[self addSubview:splashImageView];
    		[splashImageView release];
    		
    		UILabel *loadingLabel = [[UILabel alloc]initWithFrame:CGRectMake(125.0,220.0,80.0,30.0)];
    		loadingLabel.text = @"Loading...";
    		
    		loadingLabel.textColor = [UIColor grayColor];
    		loadingLabel.backgroundColor= [bgColor colorWithAlphaComponent:0.0];
    		//loadingLabel.shadowOffset = CGSizeMake(1.0,1.0);
    		//loadingLabel.shadowColor = [UIColor blackColor];
    		[self addSubview:loadingLabel];
    		[loadingLabel release];
    	
    		return self;
    	}
    	return nil;
    }
    
    -(void)dealloc
    {
    	
    	[super dealloc];
    }
    
    
    @end
    
     
  2. SwampThingTom macrumors member

    Joined:
    Jul 12, 2008
    Location:
    Fairfax, VA
    #2
    The leak is probably with the splashScreenObject itself. If it were in the init routine, Instruments would have pointed to the line in that routine that caused the problem.

    Are you releasing splashScreenObject after adding it to the subview?

    Tom
     

Share This Page