开发者

Sheet and thread memory problem

开发者 https://www.devze.com 2022-12-26 06:08 出处:网络
recently I started a project which can export some precalculated Grafix/Audio to files, for after processing.

recently I started a project which can export some precalculated Grafix/Audio to files, for after processing.

All I was doing is to put a new Window (with progressindicator and an Abort Button) in my main xib and opened it using the following code:

[NSApp beginSheet: REC_Sheet modalForWindow: MOTHER_WINDOW modalDelegate: self didEndSelector: nil contextInfo: nil];

NSModalSession session=[NSApp beginModalSessionForWindow:REC_Sheet];
RECISNOTDONE=YES;
while (RECISNOTDONE) {
    if ([NSApp runModalSession:session]!=NSRunContinuesResponse)
        break;
    usleep(100);
}

[NSApp endModalSession:session];

A Background Thread (pthread) was started earlier, to actually perform the work and save all the targas/wave file. Which worked great, but after an amount of time, it turned out that the main thread was not responding anymore and my memory footprint raised unstoppable. I tried to debug it with Instruments, and saw a lot of CFHash etc stuff growing to infinity.

By accident i clicked below the sheet, and temporary it helped, the main thread (AppKit ?) was releasing it's stuff, but just for a little time.

I can't explain it to me, first of all I thought it was the access from my thread to the Progressbar to update the Progress (intervalled at 0,5sec), so I cut it out. But even if I'm not updating anything and did nothing with the Progressbar, my Application eat up all the Memory, because of not releasing it's "Main-Event" or whatsoever Stuff.开发者_Python百科

Is there any possibility to "drain" this Main thread Memory stuff (Runloop / NSApp call?). And why the heck doesn't the Main thread respond anymore (after this simple task) ???

I don't have a clou anymore, please help !

Thanks in advance !

P.S. How do you guys implement "threaded long task" Stuff and updating your gui ???


while (RECISNOTDONE) {
    if ([NSApp runModalSession:session]!=NSRunContinuesResponse)
        break;
    usleep(100);
}

Is there a reason you're doing that? A sheet will block its parent window without you having to do anything like this. You can prevent quit within your app delegate.

If you really do need the above code for something, try creating an autorelease pool before sending the runModalSession: message, then draining it after (but before you compare to NSRunContinuesResponse and break).

0

精彩评论

暂无评论...
验证码 换一张
取 消