iDevGames Forums
Question about AutoreleasePool on GLImageWall Example - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Question about AutoreleasePool on GLImageWall Example (/thread-3185.html)



Question about AutoreleasePool on GLImageWall Example - bonanza - Jul 13, 2007 04:49 AM

Hi,
in the GLImageWall Example in SplitterBox.m
is the following Code:

Code:
//Main Event Loop
    // Now that we've got the screen, we enter a loop in which we alternately process input events and computer and render the next frame of our animation.  The shift here is from a model in which we passively receive events handed to us by the AppKit to one in which we are actively driving event processing.
    [scene setFullscreen:YES];
    while([scene fullscreen]&&!error)
    {        
        NSAutoreleasePool* pool=[[NSAutoreleasePool alloc] init]; <-------

        // Check for and process input events.
        NSEvent *event;
        while(event=[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES])
        {

.
.
.
.

Why is there an AutoreleasePool ???


Question about AutoreleasePool on GLImageWall Example - ThemsAllTook - Jul 13, 2007 05:26 AM

If your code is spinning in a busy loop for a long time (and allocating objects), an autorelease pool is useful to make sure autoreleased objects don't pile up and go nowhere. The autorelease pool created for you by NSApplicationMain() doesn't empty itself until you return to the main event loop, which this code won't do while the view is full screen, which means it's likely to be a very long time. Without the autorelease pool in that code, application memory would grow continuously in the loop (unless nothing in the loop calls or causes any autoreleases at all).


Question about AutoreleasePool on GLImageWall Example - bonanza - Jul 13, 2007 05:32 AM

Thanks you for this