Re: NSWindow alloc/dealloc problems
Re: NSWindow alloc/dealloc problems
- Subject: Re: NSWindow alloc/dealloc problems
- From: Alex Reynolds <email@hidden>
- Date: Mon, 29 Nov 2004 12:02:23 -0500
On Nov 29, 2004, at 4:42 AM, j o a r wrote:
Are you sure that the problem is not somewhere else? You mention a
"capture" button, sounds like you're using QuickTime? Are you sure
that you've removed all references to your old window from other
pieces of your code? The content view that you assign to your new
windows - how is it created? Are you sure that it's not released and
deallocated together with the first window?
The content view (targetDisplayCino) is from an NSPanel. It appears
that I do not need to do this:
targetDisplayCino = [[NSPanel alloc] init];
because it appears to be created and destroyed with the application as
a whole.
Does a [NSWindow close] or [NSWindow release] call attempt to destroy
everything inside it? I just want the NSWindow instance to go away, not
my NSView or NSPanel.
Here is the entire method I use that handles alternate presses of the
"capture" button.
// capture screen and display media or release screen
- (IBAction) cinoServerButtonPressed:(id)sender
{
NSLog(@"cinoServerButtonPressed");
if (![cinoState getTargetDisplayCaptureFlag])
{
// capture screen
if (CGDisplayCapture([cinoState getTargetDisplayID:[cinoState
getTargetDisplaySelectedIndex]]) != kCGErrorSuccess)
{
NSLog(@"Could not capture display %d", [cinoState
getTargetDisplaySelectedIndex]);
}
// change mode of captured screen to selected mode
CGDisplaySwitchToMode([cinoState getTargetDisplayID:[cinoState
getTargetDisplaySelectedIndex]],
CFArrayGetValueAtIndex(CGDisplayAvailableModes([cinoState
getTargetDisplayID:[cinoState getTargetDisplaySelectedIndex]]),
[targetDisplayMode indexOfSelectedItem]));
// attach content
windowLevel = CGShieldingWindowLevel();
cinoScreenRect = [[[NSScreen screens] objectAtIndex:[cinoState
getTargetDisplaySelectedIndex]] frame];
NSLog([[NSScreen screens] description]);
targetWindow = [[NSWindow alloc] initWithContentRect:cinoScreenRect
styleMask:NSBorderlessWindowMask backing:NSBackingStoreRetained
defer:YES];
[targetWindow setLevel:windowLevel];
[targetWindow setBackgroundColor:[NSColor blackColor]];
[targetDisplayCino setFrame:cinoScreenRect display:YES];
[targetWindow setContentView:[targetDisplayCino contentView]];
[targetWindow setReleasedWhenClosed:YES];
[targetWindow makeKeyAndOrderFront:nil];
// alter UI
[targetDisplayList setEnabled:NO];
[targetDisplayMode setEnabled:NO];
[targetDisplayToggle setTitle:[NSString
localizedStringWithFormat:@"Release"]];
// set capture flag
[cinoState setTargetDisplayCaptureFlag:YES];
}
else
{
// detach content
[targetWindow close];
// release screen
if (CGDisplayRelease([cinoState getTargetDisplayID:[cinoState
getTargetDisplaySelectedIndex]]) != kCGErrorSuccess)
{
NSLog(@"Could not release display %d", [cinoState
getTargetDisplaySelectedIndex]);
}
// change mode of captured screen to original mode
CGDisplaySwitchToMode([cinoState getTargetDisplayID:[cinoState
getTargetDisplaySelectedIndex]],
CFArrayGetValueAtIndex(CGDisplayAvailableModes([cinoState
getTargetDisplayID:[cinoState getTargetDisplaySelectedIndex]]),
[cinoState getTargetDisplayOriginalMode]));
[targetDisplayMode selectItemAtIndex:[cinoState
getTargetDisplayOriginalMode]];
// alter UI
[targetDisplayList setEnabled:YES];
[targetDisplayMode setEnabled:YES];
[targetDisplayToggle setTitle:[NSString
localizedStringWithFormat:@"Capture"]];
// set capture flag
[cinoState setTargetDisplayCaptureFlag:NO];
}
}
I think only one targetWindow is being allocated, so I don't know why
[targetWindow close] doesn't release that one object, so that the
[NSWindow alloc] can run properly.
+[NSWindow alloc] doesn't care if you have other window instances or
not - it will create a new window regardless.
It doesn't seem to want to. The program crashes at:
targetWindow = [[NSWindow alloc] initWithContentRect:cinoScreenRect
styleMask:NSBorderlessWindowMask backing:NSBackingStoreRetained
defer:YES];
on the second invocation.
Are there tools I can use to keep track of how many targetWindow
objects there really are?
You mean "how many NSWindow instances". You can ask your NSApplication
shared instance for a list of all windows in your application.
What command should I use to ask for this information?
Thanks,
Alex
_______________________________________________
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