• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Of input loops and games
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Of input loops and games


  • Subject: Re: Of input loops and games
  • From: Sherm Pendley <email@hidden>
  • Date: Wed, 21 Sep 2005 15:36:02 -0400

On Sep 21, 2005, at 2:59 PM, Hari Seldon wrote:

I've found the true cause of my memory leaks. My startGame() function
looks something like this:

- (void)startGame
{
    NSAutoreleasePool * thePool = [[NSAutoreleasePool alloc] init];
    start_move_loop();
    [thePool release];
}

I spawn a new thread in calling startGame, which makes me responsible
for creating an NSAutoreleasePool. But I realized today while
deubugging that [thePool release] doesn't get called until the game
quits, which means that tons of "temporary" NSStrings are building up
in the pool, causing a big memory drain. Is there any way to
periodically "drain" the pool?

You can "stack" as many autorelease pools as you need. When a new pool is created, it's added to the top of the stack. When an object is autoreleased, it's added to the top pool on the stack.


AppKit creates a new autorelease pool at the beginning of each iteration through its run loop, and releases that pool at the end. You could do something similar. In pseudo-code:

- (void)start_move_loop() {
    int end_loop = 0;
    while (end_loop == 0) {
        NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];

        // Call get_key() and handle game events

        [subPool release];
    }
}

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Of input loops and games
      • From: Hari Seldon <email@hidden>
References: 
 >Of input loops and games (From: Hari Seldon <email@hidden>)
 >Re: Of input loops and games (From: Jack Nutting <email@hidden>)
 >Re: Of input loops and games (From: Hari Seldon <email@hidden>)

  • Prev by Date: Re: Of input loops and games
  • Next by Date: Tracking Rect Documentation clarification please
  • Previous by thread: Re: Of input loops and games
  • Next by thread: Re: Of input loops and games
  • Index(es):
    • Date
    • Thread