Open ilyamuromets opened 9 years ago
Any chance you have a large image you are trying to set as a View background?
I set only color and background-color values with your library.
I see. What device are you using, and how much memory does it have available.
Nexus 5. It happens when available 0-3% free memory. It shows logcat.
If I disable your library my app works without crashes.
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.
Thanks for the detailed answer! Maybe there is a performance problem in my app.
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.
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/ E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: , 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)