Event handler and memory leaks

后端 未结 2 1505
無奈伤痛
無奈伤痛 2020-12-11 19:01

I analyze a VB.NET project and there are some objects (child MDI form) that are disposed, but not removed by the GC.

The MemoryProfiler analysis find, among others,

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 19:34

    There is another object which references the object that should be removed by the GC via an eventhandler. Meaning: there's another object that is still subscribed to an event of the disposed object.

    You can resolve this by unsubscribing from the event (remove the eventhandlers from the event), when you want to dispose that object.

提交回复
热议问题