Android/Java PoseLandmarker unnecessary []byte garbage
Author: calbotCreated Sep 14, 2024Updated Sep 30, 2026
Labelsplatform:androidtype:performancestat:awaiting googlertask:pose landmarker
Have I written custom code (as opposed to using a stock example script provided in MediaPipe)
Yes
OS Platform and Distribution
Android
MediaPipe Tasks SDK version
No response
Task name (e.g. Image classification, Gesture recognition etc.)
PoseLandmarker
Programming Language and version (e.g. C++, Python, Java)
Kotlin/Java
Describe the actual behavior
AndroidPacketGetter.copyRgbToBitmap calling ByteBuffer.allocateDirect creating massive amounts of byte array GC
Describe the expected behaviour
Reuse byte[] on the same thread in AndroidPacketGetter.copyRgbToBitmap
Standalone code/steps you may have used to try to get what you need
AndroidPacketGetter is misusing ByteBuffer.allocateDirect which is meant for long lived ByteBuffers. It seems to be a major memory allocation/GC area for PoseLandmarker.
Maybe these should be threadlocal cached by size (width * height) or some other way to avoid so many allocations. Or maybe the byte buffer should be passed in from PoseLandmarker.createFromOptions where AndroidPacketGetter.getBitmapFromRgb is called.Other info / Complete Logs
No response
Source: google-ai-edge/mediapipe