关闭 NSWindow 并释放内存,但通过单击按钮重新打开它

发布于 2024-10-10 02:31:50 字数 220 浏览 0 评论 0原文

我有一个要求,我需要在一段时间后显示相同的窗口。 所以我已经使用 [window setReleaseWhenClose:NO] 实现了它,但现在的问题是它一直占用 2MB 内存。

我希望这样,当我打开它时,它使用 2MB 内存,当我关闭它时,它会释放该内存,但我仍然应该能够重新打开它。

如果您有任何线索,那将会很有帮助。

谢谢

MB

I have a requirement in which I need to show same window after some time.
So i have achieved it using [window setReleaseWhenClose:NO] , but now the problem is that it keeps occupying 2MB of memory.

I want to have it like this that when i open it it uses 2MB of memory and when i close it it frees that memory, but still I should be able to re-open it.

If u have got any clues, that would be helpful.

Thanks

M.B.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生路 2024-10-17 02:31:51

如果你想释放内存,你必须在窗口关闭后释放它。如果您再次需要它,您始终可以重新加载 nib 文件。无法同时保持窗口加载和释放内存。

为了使内存管理更容易,您应该使用 NSWindowController 来管理内存。

但我不会担心 2 MiB RAM。将窗口保留在内存中可能比在需要时再次加载它更好。

If you want the memory to be released you have to release the window after it gets closed. If you need it again you always can reload the nib file. There is no way to keep the window loaded and release the memory at the same time.

To make this memory management easier you should use a NSWindowController to manage the memory.

But I wouldn’t worry about 2 MiB of RAM. Keeping the window in memory might be preferable to loading it again when it’s needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文