I work with an application that requires downloading multiple images from the Internet. I use 2 libraries: Fresco from Facebook and Picasso (In different Activity ). But OutOfMemory appears constantly when the testers use the application. There is an idea to complete the Activity immediately after leaving it. finish() along with startActivityToResult(...) do not help. I also tried System.gс() .

The application crashes after a busy memory of 60 MB. Tell me what to do?

  • Yes, you have a memory there is not eating a bitmap but not eating. We need to clear them bitmap.recycle (). And the activity and finish () ends normally. - Evgeny Karavashkin
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

GC itself will work when it is needed. Adjust image loading into memory - RGB_565 in a compartment with image loading by the size of the view, not the original image.

I have not worked with Picasso and Fresco , but with the example of Universal-Image-Loader I can say this.

  DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(android.R.color.transparent) .bitmapConfig(Bitmap.Config.RGB_565) // ΡƒΠΌΠ΅Π½ΡŒΡˆΠ°Π΅ΠΌ количСство Π±ΠΈΡ‚ΠΎΠ² Π½Π° пиксСль. .imageScaleType(ImageScaleType.IN_SAMPLE_INT) // ΠΊΡ€Π°Ρ‚Π½ΠΎΠ΅ ΡƒΠΌΠ΅Π½ΡŒΡˆΠ΅Π½ΠΈΠ΅ изобраТСния ΠΏΠΎΠ΄ Ρ€Π°Π·ΠΌΠ΅Ρ€Ρ‹ view для экономии памяти. .cacheInMemory(true) .cacheOnDisk(true) .build(); 

All this wildly saves memory. And yes, you have noodles between the activities of the GC will not save.