Remove and release subviews
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.