views:

19

answers:

1

Hi guys, I'm new to objective-c and at the moment developing a small application.

I have some memory management issues and want to ask this particular question. I have a button, appearance of which I'm changing:

for (UIView *subview in button.subviews) 
{
if (![subview isKindOfClass:[UIImageView class]]) // don't remove UIImageView, otherwise it will not be able to set background
     {
        [subview removeFromSuperview];
     }
}
[button setBackgroundImage: [[imageArray objectAtIndex:itemNumber] forState:UIControlStateNormal];
/*
    creating myView and myLabel here
*/
[button addSubview:myView];
[button addSubview:myLabel];
[myLabel release];
[myView release];

The code actually more complex, but there are no any leaks. Despite of this the number of allocated objects and used memory keep growing every time I do it. How can I solve this problem?

Thank you very much

+1  A: 

how did you measure? with instruments? did you check 'objects still alive' or are you measuring total memory / objects allocated. there is a difference.

MiRAGe
Yes, I'm using instruments and checking alive objects and memory. It looks like the quantity of objects stays still, but amount of memory is increasing
Burjua