Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
546
92
Utah
When I moved to ARC, the window pops up for a short time then disappears. The code to make the window is coded thus:
Code:
[color=#aa0d91]@implementation[/color] Document

+ ([color=#aa0d91]void[/color])openFile:([color=#5c2699]NSString[/color] *)apath
{
    [[[color=#aa0d91]self[/color] [color=#2e0d6e]alloc[/color]] [color=#26474b]initWithFile[/color]: apath];
}


- ([color=#aa0d91]IBAction[/color])reload:([color=#aa0d91]id[/color])sender
{
    {
        [color=#3f6e74]svg_t[/color] *svg;
        [color=#5c2699]clock_t[/color] t;
        [color=#3f6e74]SVGRenderContext[/color] *svg_render_context = [[[color=#3f6e74]SVGRenderContext[/color] [color=#2e0d6e]alloc[/color]] [color=#2e0d6e]init[/color]];

        [color=#26474b]svg_create[/color](&svg);
[color=#007400]//        printf("parsing...\n");[/color]
        [color=#26474b]svg_parse[/color](svg, [[color=#3f6e74]path[/color] [color=#2e0d6e]fileSystemRepresentation[/color]]);

[color=#007400]//        printf("rendering...\n");[/color]
        t=[color=#2e0d6e]clock[/color]();
        [svg_render_context [color=#26474b]prepareRender[/color]: [color=#3f6e74]scale[/color]];
        [color=#26474b]svg_render[/color](svg, &[color=#3f6e74]cocoa_svg_engine[/color], ([color=#aa0d91]__bridge[/color] [color=#aa0d91]void[/color]*)svg_render_context);
        [svg_render_context [color=#26474b]finishRender[/color]];
        t=[color=#2e0d6e]clock[/color]()-t;
[color=#007400]//        printf("done: %15.8f seconds\n",t/(double)CLOCKS_PER_SEC);[/color]

        [color=#5c2699]NSSize[/color] contextSize = [svg_render_context [color=#26474b]size[/color]];
        [[color=#3f6e74]svg_view[/color] [color=#2e0d6e]setFrame[/color]: [color=#2e0d6e]NSMakeRect[/color]([color=#1c00cf]0[/color], [color=#1c00cf]0[/color], contextSize.[color=#5c2699]width[/color], contextSize.[color=#5c2699]height[/color])];
        [[color=#3f6e74]svg_view[/color] [color=#26474b]setSVGRenderContext[/color]: svg_render_context];

        [color=#26474b]svg_destroy[/color](svg);
    }
}


- ([color=#aa0d91]id[/color])initWithFile:([color=#5c2699]NSString[/color] *)apath
{
    [color=#aa0d91]if[/color] (!([color=#aa0d91]self[/color]=[[color=#aa0d91]super[/color] [color=#2e0d6e]initWithWindowNibName[/color]: [color=#c41a16]@"Document"[/color]])) [color=#aa0d91]return[/color] [color=#aa0d91]nil[/color];
    [color=#3f6e74]path[/color] = [apath [color=#2e0d6e]copy[/color]];
    [[[color=#aa0d91]self[/color] [color=#2e0d6e]window[/color]] [color=#2e0d6e]setTitleWithRepresentedFilename[/color]: [color=#3f6e74]path[/color]];

    [color=#3f6e74]scale[/color] = [color=#1c00cf]1.0[/color];
    [[color=#aa0d91]self[/color] [color=#26474b]reload[/color]:[color=#aa0d91]nil[/color]];
    [[color=#aa0d91]self[/color] [color=#2e0d6e]showWindow[/color]:[color=#aa0d91]nil[/color]];

    [color=#aa0d91]return[/color] [color=#aa0d91]self[/color];
}


- ([color=#aa0d91]void[/color])windowWillClose:([color=#5c2699]NSNotification[/color] *)n
{
    [color=#007400]//[self autorelease];[/color]
}
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?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.