6

What Xamarin.iOS does about memory management? With usual IL we have Garbage Collector which takes care of objects not in use and reliefs programmer from calling delete. How this works when Xamarin compiles code to native? Who cleans objects which aren't used anymore?

This question answers how compilation works but doesn't explain the memory management part: How MonoTouch works?

Community
  • 1
  • 1
vladimir
  • 2,635
  • 3
  • 23
  • 26

1 Answers1

6

The answer you seek was given on the question you linked.

To summarize, the IL-to-native translation process is done ahead of time, but other pieces of the Mono runtime are still required. JIT compilation is only one of the tasks performed by the runtime, and this particular piece is incompatible with iOS' memory restrictions (writable memory pages cannot also be executable, and this is required for a JIT to function). This is, AFAIK, the only reason why ahead-of-time (AOT) compilation is required at all.

The Mono garbage collector does indeed run on iOS, it's just embedded into the binary produced by the Monotouch compiler. The produced binary contains your AOT-compiled application code as well as AOT-compiled versions of the libraries you use, and a slimmed-down version of the Mono runtime.

Community
  • 1
  • 1
cdhowie
  • 158,093
  • 24
  • 286
  • 300
  • Thanks. Somehow I wasn't able to extract this conclusion from linked question. Does it mean that due to more code to be executed and garbage collector working side-by-side with the application technically Xamarin.iOS application is slower then native (written in Obj-C) application? Is the difference big? – vladimir Apr 09 '13 at 16:21
  • @vladimir That's because the accepted answer there is *wrong.* – cdhowie Apr 09 '13 at 16:22
  • @vladimir Slower? Probably. Slower enough that the user notices? That all depends on what the application is doing. – cdhowie Apr 09 '13 at 16:25
  • Aggree. It fully depends on type of application. What about memory usage? I assume that managed objects used in application have some linear memory increase compared to native (1x is also linear). But Mono runtime obviously adds some additinal memory usage which should be more or less static (same from app to app and doesn't depend on how big the app itself). Do you have an idea what this Mono runtime memory cost is on Xamarin.iOS (for example)? – vladimir Apr 09 '13 at 16:53
  • Managed objects will be bigger, but not linearly. Managed objects include a type descriptor (which is of a constant size) and a vtable for resolution of virtual calls (which depends on the number of virtual methods on the type), for example. Monotouch apps will necessarily use more memory than an exactly-equivalent Objective-C app. Again, whether or not this is a problem depends on the application. – cdhowie Apr 09 '13 at 16:57