NSWindow's setContentView
NSWindow's setContentView
- Subject: NSWindow's setContentView
- From: Drarok Ithaqua <email@hidden>
- Date: Mon, 19 Jun 2006 04:02:50 +0100
For sake of simplicity, let's assume I want to swap the contents of
two windows, mainWindow and playlistWindow.
mainWindow contains an NSMovieView, and playlistWindow contains only
an NSTableView. I run the following code:
NSView* playView = [playlistWindow contentView];
NSView* mainView = [mainWindow contentView];
// Assuming retainCount of 1 on both views to start with...
NSLog( @"main: %d. play: %d", [mainView retainCount], [playView
retainCount] );
[playView retain]; // (2)
[mainView retain]; // (2)
[playlistWindow setContentView:mainView]; // playView gets a release
(1), mainView a retain(3)
[mainWindow setContentView:playView]; // mainView gets a release(2),
playView gets a retain(2).
[mainView release]; // (1)
[playView release]; // (1)
NSLog( @"main: %d. play: %d", [mainView retainCount], [playView
retainCount] );
Debug says this:
2006-06-19 03:59:37.103 Flix[28513] main: 1. play: 1
2006-06-19 03:59:37.126 Flix[28513] main: 2. play: 2
And then, if I call that code again, I get a crash.
I'm assuming some autoreleasing is going on, but I really don't
understand why the retainCounts are 2 when I think they should only
be 1...
This probably seems pretty pointless, but it's the best way I can
explain it at 4am.
Hope someone can shed some light, I'm tearing my hair out!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden