纸张和线程内存问题
最近我开始了一个项目,可以将一些预先计算的 Grafix/音频导出到文件中,以进行后处理。
我所做的就是在我的主 xib 中放置一个新窗口(带有进度指示器和中止按钮),并使用以下代码打开它:
[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];
较早启动后台线程(pthread),以实际执行工作并保存所有 targas /波形文件。效果很好,但经过一段时间后,结果发现主线程不再响应,并且我的内存占用量不可阻挡地增加。我尝试使用 Instruments 对其进行调试,并看到很多 CFHash 等内容增长到无穷大。
偶然我点击了工作表下方,暂时它有所帮助,主线程(AppKit?)正在释放它的东西,但只是一小段时间。
我无法向我解释它,首先我认为这是从我的线程访问进度条来更新进度(间隔为0,5秒),所以我把它删掉了。但即使我没有更新任何内容并且对进度条没有执行任何操作,我的应用程序也会耗尽所有内存,因为没有释放它的“主要事件”或任何东西。
是否有可能“耗尽”这个主线程内存内容(Runloop / NSApp 调用?)。为什么主线程不再响应(在这个简单的任务之后)???
我已经没有云了,请帮忙!
提前致谢 !
PS 你们如何实现“线程长任务”的东西并更新你的图形用户界面???
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.
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 ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你这样做有理由吗?工作表将阻塞其父窗口,而您无需执行此类操作。您可以在应用程序委托中阻止退出。
如果您确实需要上述代码,请尝试在发送 runModalSession: 消息之前创建一个自动释放池,然后在之后(但在与 NSRunContinuesResponse 进行比较并中断之前)将其耗尽)。
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 toNSRunContinuesResponse
and break).