OutOfMemoryError (heap size more than allocated)


#1

In first challenge I get this error

E/AndroidRuntime(31382): java.lang.OutOfMemoryError: (Heap Size=42851KB, Allocated=34542KB)

The reason it CrimePagerActivity creates three instances of CrimeFragment (one viewed, one to the left and one to the right) and it almost fills allowed memory limit.
When ImageFragment is created new bitmap pushes memory beyond the limit and crashes my app.

What options do I have to prevent such crashes?

Is there a way to increase memory limit in code?
Or should I reorganize all image processing by scaling and rotating image right after it was taken on camera? This option doesn’t seem legit, because it may conflict with further chapters of the book.