• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Remove and release subviews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Remove and release subviews


  • Subject: Remove and release subviews
  • From: Lorenzo <email@hidden>
  • Date: Sun, 02 May 2004 16:27:01 +0200

Hi,
I am getting crazy with allocating and releasing subviews.
I create a subview
subView = [[NSImageView alloc] initWithFrame:aFrame];
now it has retainCount = 1; right;
then I add it to the mainView
[mainView addSubview:subView];
now it has retainCount = 2; right;
Then I release all the subviews I have added to the main view
(I really have added one only subview for now)

- (void)RemoveAllObjects
{
NSArray *viewContent = [self subviews];
int i = [viewContent count];
id subView;

while(i-- > 0){
subView = [viewContent objectAtIndex:i];
NSLog(@"A: %d", [subView retainCount]);
[subView removeFromSuperviewWithoutNeedingDisplay];
NSLog(@"B: %d", [subView retainCount]);
[subView release];
NSLog(@"C: %d", [subView retainCount]);
theBox = nil;
}
}

And I get the log
A: 2
B: 2
C: 1
And I find this is so strange...!
I suppose that removeFromSuperviewWithoutNeedingDisplay should release
subView so the log B should return 1; And the log C should give error...

Could someone explain where I am wrong?


Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Remove and release subviews
      • From: j o a r <email@hidden>
  • Prev by Date: Re: NSTextView binding redisplay
  • Next by Date: Re: Remove and release subviews
  • Previous by thread: Re: NSTextView binding redisplay
  • Next by thread: Re: Remove and release subviews
  • Index(es):
    • Date
    • Thread