Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Management - Multiple Buttons and retaincount
    text
    copied!<p>i´ve created my own scrollView and added different Buttons on that View. This class <code>MyScrollView</code> was created on a ViewController. Then i´ve tested that on the iOS simulator while calling the "simulate memory warning". But nothing happens - no dealloc on that <code>MyScrollView</code> is called. So i´ve checked the retaincount on different code lines. </p> <p>Unfortunately, all the apple memory docu and different cocoa blogs didn´t help me. So it would be cool if some of you devs could help me on that..</p> <p><strong>MyScrollView.h</strong></p> <pre><code>@interface MyScrollView : UIScrollView { NSArray* photosThumb; NSArray* photosFull; NSMutableArray* photoItemsArray; } @property (nonatomic, retain) NSArray* photosThumb; @property (nonatomic, retain) NSArray* photosFull; @property (nonatomic, retain) NSMutableArray* photoItemsArray; @end </code></pre> <p><strong>MyScrollView.m</strong></p> <pre><code>@implementation MyScrollView @synthesize photoItemsArray, photosFull, photosThumb; -(id) initArraySmall:(NSArray*) _photos initArrayBig:(NSArray*) _photosBig{ self.photosThumb = _photos; self.photosFull = _photosBig; NSUInteger i, count = [self.photosThumb count]; self.photoItemsArray = [[NSMutableArray alloc] init]; for (i = 0; i &lt; count; i++) { MyButton* photoButton = [[MyButton alloc] init]; NSLog(@"MyButton 1: %d", [photoButton retainCount]); // -&gt; 1 [photoButton addTarget:nil action:@selector(buttonDown: ) forControlEvents:UIControlEventTouchUpInside]; [self.photoItemsArray addObject:photoButton]; NSLog(@"MyButton 2: %d", [photoButton retainCount]); // -&gt; 2 [photoButton release]; NSLog(@"MyButton 3: %d", [photoButton retainCount]); // -&gt; 1 [self addSubview:[self.photoItemsArray lastObject]]; NSLog(@"MyButton 4: %d", [photoButton retainCount]); // -&gt; 2 } [self.photosThumb retain]; [self.photosFull retain]; NSLog(@"photosThumb: %d photosFull: %d", [photosThumb retainCount], [photosFull retainCount]); // -&gt; retaincount 4, 0 [self.photoItemsArray release]; NSLog(@"photoItemsArray 1: %d", [self.photoItemsArray retainCount]); // -&gt; 1 } return self; } - (void)dealloc { NSLog(@"dealloc"); self.photosThumb = nil; self.photosFull = nil; self.photoItemsArray = nil; [super dealloc]; } @end </code></pre> <p><strong>Here´s my ViewController.h</strong></p> <pre><code>@interface VideoViewController : UIViewController { MyScrollView* myView; NSArray* photos; NSArray* photosBig; } @property (nonatomic, retain) MyScrollView* myView; @property (nonatomic, retain) NSArray* photos; @property (nonatomic, retain) NSArray* photosBig; @end </code></pre> <p><strong>ViewController.m</strong></p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; photos = [NSArray arrayWithObjects:@"one.png", @"two.png", @"three.png", nil]; photosBig = [NSArray arrayWithObjects:@"oneBig.png", @"twoBig.png", @"threeBig.png", nil]; self.myView = [[MyScrollView alloc] initArraySmall:photos initArrayBig:photosBig]; [self.view addSubview:self.myView]; [self.myView release]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; NSLog(@"didReceiveMemoryWarning"); [self.myView release]; self.myView = nil; } - (void)dealloc { [super dealloc]; NSLog(@"dealloc"); [self.photos release]; [self.photosBig release]; [self.photoGallery release]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload