释放内存的问题
我有一个包含以下字段的表单:(
List<String^> ^images;
PictureBox ^box;.
List<PictureBox^> ^boxes;
String ^path;
以及一些整数)。
我使用 gcnew 为每一个分配内存,但是当我关闭表单时,内存没有被释放。我以为它们会被垃圾收集;为什么他们不呢?
我还注意到一个自动生成的 Components
类型的 Container ^
变量,它在析构函数中被删除
。这是怎么回事?
编辑:哎呀,忘记了一件相当重要的事情:在我调用上述表单的主表单中,我有一个这些表单的列表(与它们进行通信)。表单关闭后,我应该如何从列表中删除该表单?
I have a form with the following fields:
List<String^> ^images;
PictureBox ^box;.
List<PictureBox^> ^boxes;
String ^path;
(as well as some ints).
I allocate the memory for each of these with gcnew
, but when I close the form, the memory is not freed. I thought they would be garbage collected; why are they not?
I also noticed an autogenerated components
variable of type Container ^
that's delete
d in the destructor. What's up with that?
EDIT: Whoops, forgot one rather important thing: In the main form from which I call the above forms, I have a List of these forms (to communicate with them). How should I remove the form from the list once it's closed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
垃圾收集是不确定的;你无法预测它何时运行。所保证的是它会“在需要时”运行;如果您绝对需要控制它何时发生,那么您可以调用
:
Garbage collection is indeterminate; you can't predict when it will run. All that's guaranteed is that it will run "when it needs to"; if you absolutely need to control when it happens, then you can call:
and