Profiling an empty single view app - memory usage keeps going up!

JoeProJoePro CAUniversity ✭✭✭
edited July 2017 in Visual Studio

The app started out using 21MB and just sat there for a little over 9 minutes, slowly increasing to 57.7MB.
How on earth is this possible?

Seems to happen on both device and simulator.

Posts

  • JoeProJoePro CAUniversity ✭✭✭

    @RodrigoMoya Any idea what could be causing this weird behaviour?

  • RodrigoMoyaRodrigoMoya ESXamarin Team Xamurai

    Well, it might be weird or not, depending on what the app does. The Mono GC doesn't free memory immediately, it does so when it needs memory, so since the memory amounts you're talking about here are insignificant (an iOS device/sim can perfectly deal with an app allocating 57MB of memory), seems the GC is not firing, because it doesn't need to.

    If you take a snapshot though, you should see memory getting decreased, as the GC does its work when taking snapshots.

    On the other hand, if the app is doing nothing, it shouldn't really increase its memory usage, unless it's doing something in the background. Best way to see it would be to take several snapshots (you can set it to take one automatically every 30 seconds, for instance) and then compare and see what new objects are added on each snapshot.

  • JoeProJoePro CAUniversity ✭✭✭

    @RodrigoMoya
    I totally agree 57mb is not a big deal, I was more concerned with the fact it kept slowly increasing while just sitting there.
    The app does not contain one single line of user code. It's built directly from the single view app template in Visual Studio for Mac.

    I did another test run, this time taking snapshots every 2 minutes. Memory keeps going up, but allocations don't change.

    Is this just a display bug with the profiler, or is memory usage really going up? This is on 1.5.4-19

  • volomaslovvolomaslov Member

    Hello guys,

    I'm facing with same memory growing with just single view app, is it related to some internal allocations and cycles?
    Memory is cleaned up with some time (6-10 mins), so feels like GC is doing his job well, but infinity memory increasing feels strange, is it expected behaviour?

  • RodrigoMoyaRodrigoMoya ESXamarin Team Xamurai

    I think it depends on the memory usage of the app, if it is not using much memory, the GC won't fire, as it just does not need more memory and hence to garbage collect.

  • ChrisDAnnunzioChrisDAnnunzio USMember ✭✭

    I am seeing similar behavior while profiling my app with the Mac Profiler v1.6.3 (and 1.6.4.30) and have so far been unable to track down any causes or definitive leaks.

    When profiling the app under Instruments, the memory usage is basically flat and stable, the way I would expect it to be. Profiling with the Xamarin Profiler on a Mac, I am seeing a very similar, slow growth chart like the one @JoePro posted.

    I was under the impression that when creating a snapshot, the profiler forces the garbage collector to run. @RodrigoMoya Is that not the case?

    Here is a screenshot of my memory usage graph when simply launching the app and letting it idle on the initial screen for about 15 minutes. The bottom window is the same build profiled with Instruments in the same way.

    Edit: Apparently I'm not allowed to upload a screenshot...

  • ChrisDAnnunzioChrisDAnnunzio USMember ✭✭

    Here is the screenshot:

    https: // us.v-cdn.net/5019960/uploads/editor/ko/ru59ttyxhb68.png

  • RodrigoMoyaRodrigoMoya ESXamarin Team Xamurai

    @ChrisDAnnunzio said:
    I am seeing similar behavior while profiling my app with the Mac Profiler v1.6.3 (and 1.6.4.30) and have so far been unable to track down any causes or definitive leaks.

    When profiling the app under Instruments, the memory usage is basically flat and stable, the way I would expect it to be. Profiling with the Xamarin Profiler on a Mac, I am seeing a very similar, slow growth chart like the one @JoePro posted.

    I was under the impression that when creating a snapshot, the profiler forces the garbage collector to run. @RodrigoMoya Is that not the case?

    >
    in theory yes, but it all depends on the specific needs of the app at that time. That is, if the GC decides it doesn't need to do a collection, it won't do it, so it's not always the case. On iOS, for instance, this seems to happen almost always happens, but not on Android.

    Here is a screenshot of my memory usage graph when simply launching the app and letting it idle on the initial screen for about 15 minutes. The bottom window is the same build profiled with Instruments in the same way.

    the chart shows the working set of the app, a good explanation of which can be seen at https://stackoverflow.com/a/1986486

    Is the app just doing nothing (that is, nothing working on the background)? If so, it might indicate unmanaged code allocating memory. In any case, I think it would be better if we displayed "current managed memory usage" in the chart, and maybe show working set/private bytes/virtual bytes in a secondary chart (or as secondary data on the main chart).

  • ChrisDAnnunzioChrisDAnnunzio USMember ✭✭

    @RodrigoMoya Thank you for your response.

    Would you mind looking at the additional Question I posted related to this issue here:

    https://forums.xamarin.com/discussion/141864/profiler-shows-steadily-increasing-ios-app-memory-usage-while-instruments-shows-flat-memory-usage#latest

    I have reviewed and am familiar with the what is included in the reported "working set" memory of the app, but that doesn't explain the results I am seeing here.

    The app is essentially idling. There is likely some minimal background activity, checking network connectivity, but there is no user interaction in these test runs, so they should be identical and are profiling the same exact build on the same physical device. This is an iOS build; I am not concerned about Android.

    What I am specifically concerned about is the discrepancy between what is reported by the Xamarin Profiler and what is reported by the Apple Instruments profiler. If as you suggest, there is some unmanaged memory being allocated, I would expect to see that memory reported under Instruments. Again, Instruments is showing flat memory usage, while Xamarin Profiler is showing a steadily increasing working set memory usage.

Sign In or Register to comment.