Question about AutoreleasePool on GLImageWall Example

Apprentice
Posts: 9
Joined: 2010.02
Post: #1
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 ???
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #2
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).
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.02
Post: #3
Thanks you for this
Quote this message in a reply
Post Reply