关闭 NSWindow 并释放内存,但通过单击按钮重新打开它
我有一个要求,我需要在一段时间后显示相同的窗口。 所以我已经使用 [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想释放内存,你必须在窗口关闭后释放它。如果您再次需要它,您始终可以重新加载 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.