开发者

Problems with freeing memory

开发者 https://www.devze.com 2023-02-18 01:36 出处:网络
I have a form with the following fields: List<String^>^images; PictureBox^box;. List<Picture开发者_StackOverflowBox^>^boxes;

I have a form with the following fields:

    List<String^>       ^images;
    PictureBox          ^box;.
    List<Picture开发者_StackOverflowBox^>   ^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 deleted 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?


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:

GC.Collect();

and

GC.WaitForPendingFinalizers();
0

精彩评论

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