View Full Version : [Resolved] Move to ARC, won't keep windows.

Madd the Sane
Mar 26, 2012, 06:21 PM
When I moved to ARC, the window pops up for a short time then disappears. The code to make the window is coded thus:
@implementation Document

+ (void)openFile:(NSString *)apath
[[self alloc] initWithFile: apath];

- (IBAction)reload:(id)sender
svg_t *svg;
clock_t t;
SVGRenderContext *svg_render_context = [[SVGRenderContext alloc] init];

// printf("parsing...\n");
svg_parse(svg, [path fileSystemRepresentation]);

// printf("rendering...\n");
[svg_render_context prepareRender: scale];
svg_render(svg, &cocoa_svg_engine, (__bridge void*)svg_render_context);
[svg_render_context finishRender];
// printf("done: %15.8f seconds\n",t/(double)CLOCKS_PER_SEC);

NSSize contextSize = [svg_render_context size];
[svg_view setFrame: NSMakeRect(0, 0, contextSize.width, contextSize.height)];
[svg_view setSVGRenderContext: svg_render_context];


- (id)initWithFile:(NSString *)apath
if (!(self=[super initWithWindowNibName: @"Document"])) return nil;
path = [apath copy];
[[self window] setTitleWithRepresentedFilename: path];

scale = 1.0;
[self reload:nil];
[self showWindow:nil];

return self;

- (void)windowWillClose:(NSNotification *)n
//[self autorelease];

As you can see, the + (void)openFile: (NSString *)apath gets called, but the Document isn't stored anywhere, so ARC automatically releases it. Is there a way to set it so that the window and/or Document class isn't autoreleased?

Madd the Sane
Mar 26, 2012, 10:03 PM
Nevermind: I moved from an NSWindowController subclass to NSDocument. That fixed it.