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 when capturing moderate amount of screens or states #393

Closed
mlilienberg opened this issue May 31, 2024 · 2 comments
Closed

Comments

@mlilienberg
Copy link

Many thanks for creating and maintaining this library.
I came across a few issues and one is that the test fails with out of memory exception when i include too many view interactions in the captureRoboGif block or when i use the rule. The

This is the stacktrace:

Java heap space
java.lang.OutOfMemoryError: Java heap space
	at java.desktop/java.awt.image.DataBufferInt.<init>(Unknown Source)
	at java.desktop/java.awt.image.Raster.createPackedRaster(Unknown Source)
	at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
	at java.desktop/java.awt.image.BufferedImage.<init>(Unknown Source)
	at com.github.takahirom.roborazzi.BitmapToBufferedImageConverter.bitmapToImage(BitmapToBufferedImageConverter.kt:20)
	at com.github.takahirom.roborazzi.BitmapToBufferedImageConverter.convert(BitmapToBufferedImageConverter.kt:14)
	at com.github.takahirom.roborazzi.AwtRoboCanvas$drawImage$1.invoke(AwtRoboCanvas.kt:50)
	at com.github.takahirom.roborazzi.AwtRoboCanvas$drawImage$1.invoke(AwtRoboCanvas.kt:48)
	at com.github.takahirom.roborazzi.AwtRoboCanvasKt.graphics(AwtRoboCanvas.kt:594)
	at com.github.takahirom.roborazzi.AwtRoboCanvasKt.access$graphics(AwtRoboCanvas.kt:1)
	at com.github.takahirom.roborazzi.AwtRoboCanvas.drawImage(AwtRoboCanvas.kt:48)
	at com.github.takahirom.roborazzi.RoborazziKt.capture(Roborazzi.kt:621)
	at com.github.takahirom.roborazzi.ImageCaptureViewAction.perform(Roborazzi.kt:587)
	at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:2)
	at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:25)
	at androidx.test.espresso.ViewInteraction.-$$Nest$mdoPerform(ViewInteraction.java)
	at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:7)
	at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at android.os.Handler.handleCallback(Handler.java:942)
	at java.base/java.lang.invoke.LambdaForm$DMH/0x0000000800295c00.invokeStatic(LambdaForm$DMH)
	at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002a2c00.guardWithCatch(LambdaForm$MH)
	at java.base/java.lang.invoke.DelegatingMethodHandle$Holder.delegate(Unknown Source)
	at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002a3c00.guard(LambdaForm$MH)
	at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002a4000.linkToCallSite(LambdaForm$MH)
	at android.os.Handler.handleCallback(Handler.java)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at java.base/java.lang.invoke.LambdaForm$DMH/0x0000000800295400.invokeSpecial(LambdaForm$DMH)
	at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002aac00.guardWithCatch(LambdaForm$MH)
	at java.base/java.lang.invoke.DelegatingMethodHandle$Holder.delegate(Unknown Source)
	at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002ac400.guard(LambdaForm$MH)
	at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002ac800.linkToCallSite(LambdaForm$MH)

I had a look at com.github.takahirom.roborazzi.RoborazziKt.capture(Roborazzi.kt:621) where the app is crashing and i am wondering if it could help to recycle the bitmaps after usage. I tried to call it from the debugger , which had no effect. I also tried to call System.gc at different places in my test but this did not help either. Only reducing the amount of screens wrapped by the call helped as interim workaround.

@takahirom
Copy link
Owner

takahirom commented May 31, 2024

Thanks! I've noticed a similar OutOfMemoryError issue was discussed in Issue #272. It might be helpful to consider some of the approaches mentioned there.

Additionally, it might be worth trying to run your tests with VisualVM to monitor memory usage and identify potential leaks.

@mlilienberg
Copy link
Author

Thanks a lot. I was not aware that unit tests require extra declaration for heap space definition. I was wondering why the changes in gradle.properties had no effect. Never stop learning. Setting the heap space might be something worth to mention in the documentation.

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