How does memory management works on Xamarin.IOS

后端 未结 2 1216
臣服心动
臣服心动 2021-02-05 09:39

I am trying understand how memory management works when using xamarin.ios and running the app on an actual iOS device. My understanding that the iOS platform does not have a gar

相关标签:
2条回答
  • 2021-02-05 09:42

    ARC is a technology that applies to source code compiled by the Objective-C compiler and it has the effect of turning every assignment like this:

    foo = bar
    

    Where "foo" and "bar" are NSObjects into the following code:

    if (foo != null)
       [foo release];
    if (bar != null)
       [bar retain]
    foo = bar;
    

    As you can see, it is just a compiler trick that rewrites your code so you do not forget to retain/release things and only applies to Objective-C.

    What Objective-C libraries use (ARC or no ARC) is not really important to MonoTouch, as far as they use the existing documented protocol for when to retain and when to release. MonoTouch just follows those rules.

    C# objects do not have the retain/release code path, and instead just use GC to determine which objects are alive.

    When Objective-C objects are surfaced to the C# world, Monotouch takes a reference (it calls retain). When the MonoTouch GC determines that an object is no longer reachable by any managed code, then the GC calls release on the object.

    0 讨论(0)
  • 2021-02-05 09:42

    There is a great summarisation in the Xamarin docs Here

    0 讨论(0)
提交回复
热议问题