Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutOfMemoryError #30

Open
ilyamuromets opened this issue Jul 30, 2015 · 7 comments
Open

OutOfMemoryError #30

ilyamuromets opened this issue Jul 30, 2015 · 7 comments

Comments

@ilyamuromets
Copy link

I get this error when I'm working in my app, not at the start app.
Nexus 5 (Android 5.1.1)

07-30 18:11:39.588 25364-25364/<my_app_package> E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: <my_app_package>, PID: 25364
java.lang.OutOfMemoryError: Failed to allocate a 712812 byte allocation with 278924 free bytes and 272KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:789)
at android.graphics.Bitmap.createBitmap(Bitmap.java:756)
at com.pixate.freestyle.cg.shapes.PXShape.renderToImage(PXShape.java:288)
at com.pixate.freestyle.styling.stylers.PXStylerContext.getBackgroundImage(PXStylerContext.java:437)
at com.pixate.freestyle.util.PXDrawableUtil.createNewDrawable(PXDrawableUtil.java:417)
at com.pixate.freestyle.styling.adapters.PXViewStyleAdapter.updateWithNewStates(PXViewStyleAdapter.java:271)
at com.pixate.freestyle.styling.adapters.PXViewStyleAdapter.updateStyle(PXViewStyleAdapter.java:246)
at com.pixate.freestyle.styling.cache.PXStyleInfo.applyTo(PXStyleInfo.java:168)
at com.pixate.freestyle.styling.PXStyleUtils.updateStyle(PXStyleUtils.java:145)
at com.pixate.freestyle.styling.PXStyleUtils.updateStyles(PXStyleUtils.java:165)
at com.pixate.freestyle.styling.PXStyleUtils.updateStyles(PXStyleUtils.java:171)
at com.pixate.freestyle.styling.PXStyleUtils.updateStyles(PXStyleUtils.java:171)
at com.pixate.freestyle.PixateFreestyle.style(PixateFreestyle.java:268)
at com.pixate.freestyle.PXHierarchyListener$PXLayoutListener.onGlobalLayout(PXHierarchyListener.java:302)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1881)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

@Shalom
Copy link
Contributor

Shalom commented Jul 30, 2015

Any chance you have a large image you are trying to set as a View background?

@ilyamuromets
Copy link
Author

I set only color and background-color values with your library.

@Shalom
Copy link
Contributor

Shalom commented Jul 30, 2015

I see. What device are you using, and how much memory does it have available.

@ilyamuromets
Copy link
Author

Nexus 5.
It happens when available 0-3% free memory. It shows logcat.

If I disable your library my app works without crashes.

@Shalom
Copy link
Contributor

Shalom commented Jul 30, 2015

The library has some memory consumption that is 'natural' to its work. As you can see from the stacktrace, there is a rendering of the background into a Bitmap, and that takes memory. The allocated Bitmap size in that case would be the size of the View you are trying to apply a background to. In case your device is that tight on memory, you should take that into account.

Saying that does not mean that the library cannot be improved :) In cases where the CSS only defines a color, and not an image or a gradient color, it can be modified to set the color directly on the View (instead of using a backgroud bitmap). This will take some work, and you are welcome to look into the code in case you are interested.

@ilyamuromets
Copy link
Author

Thanks for the detailed answer!
Maybe there is a performance problem in my app.

@ilyamuromets
Copy link
Author

I found steps to reproduce:
I set PixateFreestyle.setStyleClass(view, class) for a few view (about 8-10 views). My app starts with default.css then I click a button to download user.css from server and apply it. I edit user.css on server and click again a button to download. To apply new styles I use following PXStyleUtils.updateStyles(android.R.id.content, true).
After a few clicks on a button my app crashes with OutOfMemoryError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants