Reputation: 1254
I have a cocoa application which creates a window.
Now, in some other part of the application, I want to create another window from a class
Following is the code I am following,
in the.h
file of the class I have defined:
NSWindow* m_NSWindow;
in the .cpp
file, inside a function (createWindow
) I have the following code:
NSRect windowRect = {406,229,886,592};
m_NSWindow = [[NSWindow alloc] intiwithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]autorelease];
[m_NSWindow setTitle:@"myWindow"];
[m_NSWindow makeKeyAndOrderFront:nil];
Can anyone point to what I am doing wrong here?
Upvotes: 0
Views: 47
Reputation:
Calling autorelease
on the window causes its reference count to be decremented to zero at the end of the current autorelease pool (probably when processing of the current event ends, if not sooner). This causes it to be deallocated, making it disappear.
Don't autorelease
objects unless you want them to go away.
Upvotes: 1