1

When I run xcode instruments and I profile on the emulator, my UiViewControllers Dispose methods are being called instantly after the view is removed. But when I run the app on the device, the dispose methods of all the UiViewController are never being called!. Or are called very slowly and the memory gets too high.

I don't know why this is happening. The problem is that the only way to get the app, in the device, to call the dipose methods is when I manually perform a Gc.Collect() in the AppDelagate ReceiveMemoryWarning and DidEnterBackground(). When any of those methods executes, the memory drops from 140MB+ to 70MB.

This is the image of the memory when app is running on the emulator. Emulator Memory Allocation

And when I run the app on the device. Device Memory Allocations

As you can see on the emulator the dispose methods are being called every time a UIviewcontroller is remove. But in the device, the dispose methods are never called. The drop that you see in the image of the device is when the app goes to beckground and I manually call a GC.Collect().

Why isn't doing it automatically in the ios device, like it does in the emulator?

I am very new to xamarin, I have spent 4 days trying to figure this out. I really don't know what to do.

I hope someone can help me.

1 Answer 1

1

When running Xamarin.iOS in debug mode on the simulator, there is a thread that continuously calls GC.Collect() every few seconds so the garbage collections happens way more often than on real device.

This is mostly to help you finding bugs in your code faster (like accessing a managed reference that is already gone). So this is the reason you are not seeing the collection happen as often as it happens on simulator when deploying to device.

You should not worry too much about collections not happening as often, GC heuristics will determine when it should happen, the times you do need to "worry" are when you are working with big managed objects like images etc. but creating those objects inside a using statement should be enough.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.