Question

I stuck in a problem, checked out many answers for a few days. My problem is when i choose profile>Leaks in Xcode, i see UILabel(CALayer) is always getting bigger in Live Bytes. Is it normal or is it a leak? what can i do about it? It is getting bigger when i change class and back to class which has these labels. Its like they are allocating over and over again but not release old ones.

i set my labels in h. file like that

@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling1;
@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling2;
@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling3;
@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling4;

and ,

- (void)viewDidUnload
{
    [super viewDidUnload];

    self.lblNumbersSpelling1=nil;
    self.lblNumbersSpelling2=nil;
    self.lblNumbersSpelling3=nil;
    self.lblNumbersSpelling4=nil;
    self.lblRecordSayfasiNot=nil;
   // Release any retained subviews of the main view.
}

i did that and i m not sure if it is necessary what i did in viewDidUnload method. I use Xcode 5. Thanks in advance.

Was it helpful?

Solution

I experienced the same problem with my application with UILabel(CALayer) increasing in memory usage in Xcode's profile tool. At the end of the day, UILabel(CALayer) increasing in memory ended up being a symptom of a memory leak caused by another issue (specifically a strong reference to a delegate).

I would check the following to make sure another is issue isn't causing the UILabel(CALayer) to be retained:

  1. Invalidate any NSTimers
  2. Remove any observers to NSNotificationCenter
  3. Make sure you are using weak references to self in blocks
  4. Make sure that any delegate properties use weak references

Source: http://www.reigndesign.com/blog/debugging-retain-cycles-in-objective-c-four-likely-culprits/

OTHER TIPS

viewDidUnload is deprecated in iOS6 and later.

Probably you want do this:

- (void)dealloc
{
    _lblNumbersSpelling1=nil;
    _lblNumbersSpelling2=nil;
    _lblNumbersSpelling3=nil;
    _lblNumbersSpelling4=nil;
    _lblRecordSayfasiNot=nil;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top