0

My application crashes after the following message in the log file:

[dalvikvm-heap] Forcing collection of SoftReferences for 4320012-byte allocation [dalvikvm-heap] Out of memory on a 4320012-byte allocation.

App does not crash when I use color instead of images for pages background. Looks like the memory allocated for the background image is not freed when the next page is opened. I set the page background as following:

<resources>
  <style name="Theme.AppPage" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splash_final</item>
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

and then in View.cs file:

[Activity (Theme = "@style/Theme.AppPage", NoHistory = false)]
public class MainMenuView : MvxActivity

As you may spotted I also use MvvmCross, maybe the issue is related to this framework.

Can someone help me with this?

Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87
  • possible duplicate of [SplashScreen using PNG image leads to Android.Views.InflateException followed by OutOfMemory](http://stackoverflow.com/questions/17729515/splashscreen-using-png-image-leads-to-android-views-inflateexception-followed-by) – Stuart Feb 08 '14 at 18:12
  • also try lots of other hits on here - e.g. http://stackoverflow.com/questions/18385362/high-resolution-image-outofmemoryerror - using smaller images and ensuring that `inPurgable` is used may help. Note also that different android versions behave differently - there's a good but low-level talk on image memory management from 2011 in http://dubroy.com/blog/google-io-memory-management-for-android-apps/ – Stuart Feb 08 '14 at 18:17
  • Ok, I checked all these links and did not found good enough solution for me. Cheesebaron from the first link suggests using Theme with the background (and I already do it) and passing ActivityFlags.NewTask | ActivityFlags.ClearWhenTaskReset options to the intent, and event this solution is not 100% reliable. Since I'm using MvvmCross I do not even have control over the code that starts new activities, I just use commands like ShowViewModel (); in ViewModels... Do I need to fork and change the code of the framework to perform SUCH a simple task? – Aleksei Petrenko Feb 08 '14 at 22:36
  • I just cannot beleive that this is not working out-of-the box... Well, there are billions android devices and hundreds of thousands of apps. And we cannot use images as a page background? That is just miserable... – Aleksei Petrenko Feb 08 '14 at 22:38
  • Thanks - I don't think forking will help you - this has nothing to do with ShowViewModel or with MvvmCross - it's a basic Android memory management question. – Stuart Feb 09 '14 at 10:12
  • Stuart, thank you for all help, but such things are always dissapointing. Do actually NewTask & ClearWhenTaskReset options mean anything? I mean is there a way to make this working without leaving Xamarin & C#? – Aleksei Petrenko Feb 09 '14 at 13:53
  • Those Intent options mean exactly the same thing as they do in Java. Stackoverflow is asking me to `Please avoid extended discussions in comments` so over and out from me here :/ – Stuart Feb 09 '14 at 14:40

0 Answers0