MonoTouch/MT Garbage Collector: how to correctly release my views/class members (simple example)?

后端 未结 2 1093
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 17:19

Have a look at the sample below which is not completely implemented but demonstrates what I\'m talking about:

public class MyClass : UIView
{
  private UIVie         


        
2条回答
  •  星月不相逢
    2021-01-13 17:37

    The answer is yes, the garbage collector will now consider the two previous instances of the objects to not be reachable from anywhere, and will be collected the next time the GC runs.

    You do not need to call Dispose() manually. The only reason to call Dispose() manually is in cases where you know that the object you are pointing to is some large object and you want to make sure that the memory is released immediately, and not wait for the GC to kick-in at some point in the future.

    What happens when you call Dispose () on the object, is that we internally release the reference to the Objective-C object and we set the Handle property on the object to null. This means that if you try to call another method on a disposed object, you will get a nice exception.

提交回复
热议问题