Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does memory management works on Xamarin.IOS

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 garbage collector, but the platform uses ARC (Automatci Reference Counting).

Is it true that the compiled app will be using ARC instead of garbage collection?

like image 235
gyurisc Avatar asked Aug 05 '13 11:08

gyurisc


People also ask

How does xamarin iOS work?

Xamarin.iOS Xamarin uses Selectors to expose Objective-C to managed C# and Registrars to expose managed C# code to Objective-C. Selectors and Registrars collectively are called "bindings" and allow Objective-C and C# to communicate. For more information, see Xamarin. iOS architecture.

Is xamarin good for iOS?

Xamarin allows you to create flawless experiences using platform-specific UI elements. It's also possible to build cross-platform apps for iOS, Android, or Windows using Xamarin. Forms tool, which converts app UI components into the platform-specific interface elements at runtime.

What is xamarin profiler used for?

Xamarin Profiler is a tool developed by Microsoft that helps the developers to analyze the app's behavior, and its memory allocations with the help of a visual studio. It is a graphical interface that supports doing profiling in android, ios, tvos, mac applications in mac and android, ios, tvos applications in windows.


1 Answers

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.

like image 199
miguel.de.icaza Avatar answered Oct 14 '22 01:10

miguel.de.icaza