FROM : j o a r
DATE : Sun Dec 19 09:51:11 2004
On 2004-12-19, at 08.29, Julian Pellico wrote:
> When this method gets run, every time through the loop the retain
> count is the same in the 2 log lines.
Why do you check this in the first place? Do you suspect that there is
a leak? What made you suspicious of that? Have you tracked it with
ObjectAlloc?
What if you write that method like this:
- (void) removeMyViews
{
for (int i = 0; i < [myViewControllers count]; i++)
{
NSView *aView = [[myViewControllers objectAtIndex: i] view];
NSLog(@"--- 1 --- %@ retainCount: %u, superview: %@", aView, [aView
retainCount], [aView superview]);
[aView removeFromSuperview];
NSLog(@"--- 2 --- retainCount: %u, superview: %@", [aView
retainCount], [aView superview]);
}
[myViewControllers removeAllObjects];
}
Does it make any difference if you replace "removeFromSuperview" with
"removeFromSuperviewWithoutNeedingDisplay"?
> Isn't this contrary to the documentation of NSView?
My advice is always that you shouldn't try to track retain count like
that. What if it's autoreleased? The last thing you should expect is a
bug in the frameworks. Of course it happens, but it's far more likely
that you have a bug in your code. Especially when it's old and often
used code like "removeFromSuperview".
j o a r
DATE : Sun Dec 19 09:51:11 2004
On 2004-12-19, at 08.29, Julian Pellico wrote:
> When this method gets run, every time through the loop the retain
> count is the same in the 2 log lines.
Why do you check this in the first place? Do you suspect that there is
a leak? What made you suspicious of that? Have you tracked it with
ObjectAlloc?
What if you write that method like this:
- (void) removeMyViews
{
for (int i = 0; i < [myViewControllers count]; i++)
{
NSView *aView = [[myViewControllers objectAtIndex: i] view];
NSLog(@"--- 1 --- %@ retainCount: %u, superview: %@", aView, [aView
retainCount], [aView superview]);
[aView removeFromSuperview];
NSLog(@"--- 2 --- retainCount: %u, superview: %@", [aView
retainCount], [aView superview]);
}
[myViewControllers removeAllObjects];
}
Does it make any difference if you replace "removeFromSuperview" with
"removeFromSuperviewWithoutNeedingDisplay"?
> Isn't this contrary to the documentation of NSView?
My advice is always that you shouldn't try to track retain count like
that. What if it's autoreleased? The last thing you should expect is a
bug in the frameworks. Of course it happens, but it's far more likely
that you have a bug in your code. Especially when it's old and often
used code like "removeFromSuperview".
j o a r
| Related mails | Author | Date |
|---|---|---|
| Julian Pellico | Dec 19, 08:29 | |
| j o a r | Dec 19, 09:51 | |
| Julian Pellico | Dec 20, 20:04 | |
| John C. Randolph | Dec 20, 20:50 | |
| mmalcolm crawford | Dec 20, 21:15 | |
| John C. Randolph | Dec 20, 22:26 |






Cocoa mail archive

