0

we are developing an app with Xamarin.iOS, which is rendering real time data. So more or less every second a new location is received from CLLocationManager() and then a map is rendered on the screen with complex and changing information using CoreGraphics and UIKit.

There is a memory leak, meaning depending on complexity of the rendering, the app is giving MemoryWarning after some time, usually 10-100 minutes, and then it crashes. We can't use Xamarin.Profiler because we can't effort VS Enterprise and we don't understand Xcode Instruments, which is in Xcode 13 even more unclear.

So what we are doing, we are systematically skipping code-blocks, run app on real device simulating locations and wait, until MemoryWarnings are starting.

This somehow works, its just very time consuming.

My question is now:

Is there a way to monitor memory consumption/growth in iOS? To see it raising with each loop? Something like:

Console.WriteLine("Current mem: " + GetCurrentIosMemoryConsumtion());

I would like to see the value, which is internally growing and then triggering the ReceiveMemoryWarning event.

Edit: I tried again Instruments, but its freezing the app after 2 minutes. By that time there was 7GiB allocated and freed up again. Only 124MiB persistent so far. Screenshot from Instruments

Tom
  • 190
  • 3
  • 18

1 Answers1

0

I think learning about Xcode instruments might help. And Xcode always shows you how much memory is used.

Turn all reasonable warnings on. The problem is often a reference cycle, and you’ll get warnings for that. (Reference cycle prevents memory from being released). Look if you have any delegates that are not weak. Or whether you collect objects in an array that is never cleaned up.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • My problem with Xcode instruments is, that is does not show me any useful stacktrace. I see mainly assembler code, sometimes some native ios-calls, but never something, that is pointing me in my xamarin-c# code. – Tom Nov 14 '21 at 13:51
  • Next problem is, that with Instruments connected the app is running different, crashing or freezing often and quickly. I believe, Instruments and Xamarin are not really working good together – Tom Nov 14 '21 at 15:00
  • I was working now a while with Xcode-Instruments, 13.0 and as @gnasher729 recommended, it really seems to be useful. But it does not run long enough. After 1-2 minutes connected to the app, the app freezes and no more data is collected. Without Instruments the app runs at least 30min, before the memory warning is triggert. Any ideas, how to be able to let the app longer in Instruments? – Tom Nov 15 '21 at 14:13
  • Try the steps in this link :https://stackoverflow.com/questions/32455689/apple-instruments-stops-working-when-tracing-ios-allocations. – ColeX Nov 18 '21 at 06:11
  • Thanks @ColeX-MSFT, unfortunate no luck. – Tom Nov 18 '21 at 13:08
  • So coming back to my initial question: Is there a function in iOS-Api so that I can check for current memory consumption in my code? Would speed up the try-and-error a lot. – Tom Nov 18 '21 at 13:13
  • Kindly take a look at https://stackoverflow.com/questions/40991912/how-to-get-memory-usage-of-my-application-and-system-in-swift-by-programatically/40992791 ,https://stackoverflow.com/questions/787160/programmatically-retrieve-memory-usage-on-iphone – ColeX Nov 19 '21 at 05:23
  • Thanks again @ColeX-MSFT, this looks promising, just it seems that the function in this code are not available from mono. Uff, this task is huge, I wish, Instruments would just work... – Tom Nov 19 '21 at 17:05
  • If the same code is not available from mono , I suggest you create [binding library](https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough) and use it in xamarin . – ColeX Nov 22 '21 at 09:38