0

I have an application made which draws a square on the screen. The user can move the square around, increase its width and height using his/her finger (touch events) etc etc. The user is also able to add any number of squares and move them separately.

The app works fine for most of the part but sometimes it crashes and gives this below error

05-09 11:32:49.488: E/AndroidRuntime(24826): FATAL EXCEPTION: main
05-09 11:32:49.488: E/AndroidRuntime(24826): Process: com.example, PID: 24826
05-09 11:32:49.488: E/AndroidRuntime(24826): java.lang.OutOfMemoryError
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.graphics.Bitmap.nativeCreate(Native Method)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.graphics.Bitmap.createBitmap(Bitmap.java:835)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.graphics.Bitmap.createBitmap(Bitmap.java:779)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.example.Square.isClicked(Square.java:478)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.example.EditBubbleView$2.onTouch(EditBubbleView.java:378)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.View.dispatchTouchEvent(View.java:7731)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2238)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.View.dispatchPointerEvent(View.java:7916)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4031)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3910)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3510)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3479)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3586)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3487)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3643)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3510)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3479)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3487)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5728)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5659)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5630)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5808)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.os.MessageQueue.nativePollOnce(Native Method)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.os.MessageQueue.next(MessageQueue.java:138)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.os.Looper.loop(Looper.java:123)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at android.app.ActivityThread.main(ActivityThread.java:5102)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at java.lang.reflect.Method.invoke(Method.java:515)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
05-09 11:32:49.488: E/AndroidRuntime(24826):    at dalvik.system.NativeStart.main(Native Method)

Can any one tell me how to resolve this. Thanks :)

8
  • Profile your application to see where it may have a memory leak. Commented May 9, 2014 at 6:14
  • Put your code where you got this crashed? Commented May 9, 2014 at 6:14
  • 1
    could you show code mentioned in error? Square and EditBubbleView Commented May 9, 2014 at 6:15
  • The stack trace shows that you are creating a BITMAP. What type of BITMAP are you creating and how big is it? Might exceed the memory available on your device. Commented May 9, 2014 at 6:17
  • 1
    Make your Bitmap variable as global. Also in your manifest set largeHeap value to true. If still the issue persists, then do sampling. Commented May 9, 2014 at 6:24

2 Answers 2

1

It is the case of memory leak. First of all check out your code at these two

at com.example.Square.isClicked(Square.java:478)05-09 11:32:49.488: E/AndroidRuntime(24826):    
at com.example.EditBubbleView$2.onTouch(EditBubbleView.java:378)

Whether these two method are getting called and same time???? and if possible then paste your code over here so that we can have a look on that.

Sign up to request clarification or add additional context in comments.

Comments

0

You can write this to your manifest.xml file.

android:largeHeap="true"

4 Comments

That may work but would likely just hide the issue. Better to profile and test first to make sure it's needed.
the docs also warn that it is necessary to understand whether you app really needs largeHeap
this will be my last resort
@Droider developer.android.com/training/articles/memory.html. Never request a large heap simply because you've run out of memory and you need a quick fix—you should use it only when you know exactly where all your memory is being allocated and why it must be retained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.