Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Xamarin.iOS does with memory management when it compiles C# to native code?

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?

like image 888
vladimir Avatar asked Apr 09 '13 16:04

vladimir


People also ask

How does compilation work for Xamarin?

Xamarin. Android applications compile from C# into Intermediate Language (IL) which is then Just-in-Time (JIT) compiled to a native assembly when the application launches. Xamarin. Android applications run within the Mono execution environment, side by side with the Android Runtime (ART) virtual machine.

Does Xamarin use C#?

Xamarin is an open source app platform from Microsoft for building modern & performant iOS and Android apps with C# and . NET.

How Xamarin is used for native Android and iOS development example?

Xamarin Forms enable fast prototyping with built-in UI libraries, adapted both to Android and iOS; Rich access to native APIs – just like in native apps, you can get access to the user's Bluetooth, camera, microphone. Features that use these API can be written in a specific language for faster performance.

How does Xamarin help mobile development?

Xamarin allows developers to develop native applications for Android, iOS and Windows Phone platforms, with a single codebase, i.e. C# and a single IDE, i.e. Visual Studio . Thus, a developer can be able to develop native mobile applications without knowing Java, Kotlin, Objective-C or Swift.


1 Answers

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.

like image 90
cdhowie Avatar answered Nov 01 '22 13:11

cdhowie