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
StartImageStream causes memory leak, frequently crashes [camera_android_camerax] #145893
Comments
Hi @jamesstevensdev Sample code// Assign the format group based on the platform
import 'dart:io';
import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:flutter/material.dart';
import 'camera_controller.dart';
void main() {
runApp(const MaterialApp(home: Home()));
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
_onClick();
},
),
);
}
void _onClick() async {
final formatGroup = Platform.isIOS ? ImageFormatGroup.bgra8888 : ImageFormatGroup.yuv420;
// Set the target camera resolution
ResolutionPreset resolutionPreset = ResolutionPreset.ultraHigh;
// Get the correct camera lens
final cameras = await availableCameras();
final description = cameras.firstWhere(
(c) => c.lensDirection == CameraLensDirection.back,
);
// Create a camera controller
final CameraController controller = CameraController(
description,
resolutionPreset,
enableAudio: false,
imageFormatGroup: formatGroup,
);
// Initialize the controller
await controller.initialize();
// Start the image stream with an empty callback
await controller.startImageStream((image) {
return;
});
// Wait for 60 seconds
await Future.delayed(const Duration(seconds: 60));
// Stop and dispose the camera controller
await controller.stopImageStream();
await controller.dispose();
}
}
I'm not sure if your sample code is the same or not. Could you retry and confirm? |
@huycozy Hello, the code is the same. The memory crash doesn’t happen every time. Additionally, without the camerax package the camera package never caused these sorts of spikes. Often the types of phones used by our customers will have a small amount of RAM and so even spiking to 2GB is enough to cause a crash. I tested this on 3 different Android phones (low and high end phones). Let me know if you would like more information. If needed I can send you a larger code sample to test. |
Checking this a few times, the crash ("Lost connection to device") also occurs to me as well. Checked this on Output log✓ Built build/app/outputs/flutter-apk/app-profile.apk (19.8MB).
Debug service listening on ws://127.0.0.1:57085/srzT7gmuaLQ=/ws
V/PhoneWindow( 9964): DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@ba18da6, this = DecorView@15613e7[MainActivity]
D/ViewRootImpl( 9964): enqueueInputEventMotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=920.0, y[0]=2123.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3401619, downTime=3401619, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 9964): processMotionEvent MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=920.0, y[0]=2123.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3401619, downTime=3401619, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 9964): dispatchPointerEvent handled=true, event=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=920.0, y[0]=2123.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3401619, downTime=3401619, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 9964): processMotionEvent MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=920.0, y[0]=2123.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3401699, downTime=3401619, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 9964): dispatchPointerEvent handled=true, event=MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=920.0, y[0]=2123.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3401699, downTime=3401619, deviceId=-1, source=0x1002, displayId=0 }
I/OplusCameraManager( 9964): saveOpPackageName, mOpPackageName: io.flutter.plugins.cameraxexample
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/OplusCameraManagerGlobal( 9964): Connecting to camera service
I/CameraManagerGlobal( 9964): Connecting to camera service
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/chatty ( 9964): uid=10331(io.flutter.plugins.cameraxexample) CameraX-core_ca identical 4 lines
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
D/CameraRepository( 9964): Added camera: 0
I/Camera2CameraInfo( 9964): Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/CameraManagerGlobal( 9964): postSingleUpdate onCameraAvailable=0
I/CameraManagerGlobal( 9964): postSingleUpdate onCameraAvailable=1
D/CameraRepository( 9964): Added camera: 1
I/Camera2CameraInfo( 9964): Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/CameraManagerGlobal( 9964): postSingleUpdate onCameraAvailable=0
I/CameraManagerGlobal( 9964): postSingleUpdate onCameraAvailable=1
D/CameraValidator( 9964): Verifying camera lens facing on RMX2001L1, lensFacingInteger: null
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=270, isOppositeFacing=false, result=270
I/BufferQueueConsumer( 9964): [](id:26ec00000000,api:0,p:-1,c:9964) connect(): controlledByApp=true
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
I/chatty ( 9964): uid=10331(io.flutter.plugins.cameraxexample) identical 3 lines
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/DynamicRangeResolver( 9964): Resolved dynamic range for use case androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c275 to no compatible HDR dynamic ranges.
D/DynamicRangeResolver( 9964): DynamicRange@5f420fe{encoding=UNSPECIFIED, bitDepth=0}
D/DynamicRangeResolver( 9964): ->
D/DynamicRangeResolver( 9964): DynamicRange@b9fd4b9{encoding=SDR, bitDepth=8}
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/DeferrableSurface( 9964): Surface created[total_surfaces=1, used_surfaces=0](androidx.camera.core.processing.SurfaceEdge$SettableSurface@d73a05f}
D/DeferrableSurface( 9964): Surface created[total_surfaces=2, used_surfaces=0](androidx.camera.core.SurfaceRequest$2@bdbe37b}
D/DeferrableSurface( 9964): New surface in use[total_surfaces=2, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@bdbe37b}
D/DeferrableSurface( 9964): use count+1, useCount=1 androidx.camera.core.SurfaceRequest$2@bdbe37b
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/ImageCapture( 9964): createPipeline(cameraId: 0, streamSpec: StreamSpec{resolution=3840x2160, dynamicRange=DynamicRange@b9fd4b9{encoding=SDR, bitDepth=8}, expectedFrameRateRange=[0, 0], implementationOptions=androidx.camera.camera2.impl.Camera2ImplConfig@4bb3c57})
I/BufferQueueConsumer( 9964): [](id:26ec00000001,api:0,p:-1,c:9964) connect(): controlledByApp=true
D/DeferrableSurface( 9964): Surface created[total_surfaces=3, used_surfaces=1](androidx.camera.core.impl.ImmediateSurface@2656344}
I/BufferQueueConsumer( 9964): [](id:26ec00000002,api:0,p:-1,c:9964) connect(): controlledByApp=true
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032 ACTIVE
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
I/BufferQueueConsumer( 9964): [](id:26ec00000003,api:0,p:-1,c:9964) connect(): controlledByApp=true
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
D/UseCaseAttachState( 9964): Active and attached use case: [] for camera: 0
D/DeferrableSurface( 9964): Surface created[total_surfaces=4, used_surfaces=1](androidx.camera.core.impl.ImmediateSurface@6f76fb0}
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1743708(32MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 3333KB/6667KB, paused 174us total 111.500ms
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389 ACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032 ACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182 INACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [] for camera: 0
D/UseCaseAttachState( 9964): Active and attached use case: [] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use cases [androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389, androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182] now ATTACHED
D/UseCaseAttachState( 9964): All use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389, androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182] for camera: 0
D/UseCaseAttachState( 9964): Active and attached use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Resetting Capture Session
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Releasing session in state INITIALIZED
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Attempting to force open the camera.
D/CameraStateRegistry( 9964): tryOpenCamera(Camera@355a1bc[id=0]) [Available Cameras: 1, Already Open: false (Previous state: null)] --> SUCCESS
D/CameraStateRegistry( 9964): Recalculating open cameras:
D/CameraStateRegistry( 9964): Camera State
D/CameraStateRegistry( 9964): -------------------------------------------------------------------
D/CameraStateRegistry( 9964): Camera@2b57fa7[id=1] UNKNOWN
D/CameraStateRegistry( 9964): Camera@355a1bc[id=0] OPENING
D/CameraStateRegistry( 9964): -------------------------------------------------------------------
D/CameraStateRegistry( 9964): Open count: 1 (Max allowed: 1)
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Opening camera.
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Transitioning camera internal state: INITIALIZED --> OPENING
D/CameraStateMachine( 9964): New public camera state CameraState{type=OPENING, error=null} from OPENING and null
D/CameraStateMachine( 9964): Publishing new public camera state CameraState{type=OPENING, error=null}
D/UseCaseAttachState( 9964): All use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389, androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182] for camera: 0
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/chatty ( 9964): uid=10331(io.flutter.plugins.cameraxexample) CameraX-core_ca identical 1 line
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
D/CameraOrientationUtil( 9964): getRelativeImageRotation: destRotationDegrees=0, sourceRotationDegrees=90, isOppositeFacing=true, result=90
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/OplusCameraManagerGlobal( 9964): setClientInfo, packageName: io.flutter.plugins.cameraxexample, uid: 10331, pid: 9964
I/OplusCameraUtils( 9964): current activityName: io.flutter.plugins.cameraxexample.MainActivity
I/OplusCameraUtils( 9964): getComponentName, componentName: io.flutter.plugins.cameraxexample/io.flutter.plugins.cameraxexample.MainActivity, packageName:io.flutter.plugins.cameraxexample, activityName:io.flutter.plugins.cameraxexample.MainActivity
E/CameraManagerGlobal( 9964): Camera 5 is not available. Ignore physical camera status change
E/CameraManagerGlobal( 9964): Camera 6 is not available. Ignore physical camera status change
I/CameraManagerGlobal( 9964): postSingleUpdate onCameraAvailable=0
I/CameraManagerGlobal( 9964): postSingleUpdate onCameraAvailable=0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389 ACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032 ACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182 INACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Use case androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182 ACTIVE
D/UseCaseAttachState( 9964): Active and attached use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389, androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182] for camera: 0
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} CameraDevice.onOpened()
D/Camera2CameraImpl( 9964): {Camera@355a1bc[id=0]} Transitioning camera internal state: OPENING --> OPENED
D/CameraStateRegistry( 9964): Recalculating open cameras:
D/CameraStateRegistry( 9964): Camera State
D/CameraStateRegistry( 9964): -------------------------------------------------------------------
D/CameraStateRegistry( 9964): Camera@2b57fa7[id=1] UNKNOWN
D/CameraStateRegistry( 9964): Camera@355a1bc[id=0] OPEN
D/CameraStateRegistry( 9964): -------------------------------------------------------------------
D/CameraStateRegistry( 9964): Open count: 1 (Max allowed: 1)
D/CameraStateMachine( 9964): New public camera state CameraState{type=OPEN, error=null} from OPEN and null
D/CameraStateMachine( 9964): Publishing new public camera state CameraState{type=OPEN, error=null}
D/UseCaseAttachState( 9964): All use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389, androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182] for camera: 0
D/UseCaseAttachState( 9964): Active and attached use case: [androidx.camera.core.ImageCapture-930c0a3e-5bcb-4c5b-96d2-7a613838f96667328032, androidx.camera.core.Preview-10cfc2ee-72fb-4a6a-93c5-551d9974c2758071389, androidx.camera.core.ImageAnalysis-b28daf6c-3d09-42c5-9e9d-c6d3c80549118289182] for camera: 0
D/SyncCaptureSessionBase( 9964): [androidx.camera.camera2.internal.SynchronizedCaptureSessionBaseImpl@a806c41] getSurface...done
D/CaptureSession( 9964): Opening capture session.
D/DeferrableSurface( 9964): New surface in use[total_surfaces=4, used_surfaces=2](androidx.camera.core.processing.SurfaceEdge$SettableSurface@d73a05f}
D/DeferrableSurface( 9964): use count+1, useCount=1 androidx.camera.core.processing.SurfaceEdge$SettableSurface@d73a05f
D/DeferrableSurface( 9964): New surface in use[total_surfaces=4, used_surfaces=3](androidx.camera.core.impl.ImmediateSurface@2656344}
D/DeferrableSurface( 9964): use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@2656344
D/DeferrableSurface( 9964): New surface in use[total_surfaces=4, used_surfaces=4](androidx.camera.core.impl.ImmediateSurface@6f76fb0}
D/DeferrableSurface( 9964): use count+1, useCount=1 androidx.camera.core.impl.ImmediateSurface@6f76fb0
I/BufferQueueProducer( 9964): [SurfaceTexture-0-9964-0](id:26ec00000000,api:4,p:1118,c:9964) connect(): api=4 producerControlledByApp=true
I/BufferQueueProducer( 9964): [ImageReader-3840x2160f100m4-9964-0](id:26ec00000001,api:4,p:1118,c:9964) connect(): api=4 producerControlledByApp=false
I/BufferQueueProducer( 9964): [ImageReader-3840x2160f23m4-9964-1](id:26ec00000002,api:4,p:1118,c:9964) connect(): api=4 producerControlledByApp=false
D/CaptureSession( 9964): Attempting to send capture request onConfigured
D/CaptureSession( 9964): Issuing request for session.
D/Camera2CaptureRequestBuilder( 9964): createCaptureRequest
D/CaptureSession( 9964): CameraCaptureSession.onConfigured() mState=OPENED
D/CaptureSession( 9964): CameraCaptureSession.onReady() OPENED
I/.cameraxexampl( 9964): Background concurrent copying GC freed 409(88KB) AllocSpace objects, 2(23MB) LOS objects, 34% free, 46MB/70MB, paused 267us total 108.698ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 667(106KB) AllocSpace objects, 6(27MB) LOS objects, 0% free, 105MB/105MB, paused 17.702ms total 140.412ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 434(108KB) AllocSpace objects, 9(47MB) LOS objects, 0% free, 113MB/113MB, paused 14.536ms total 90.357ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 430(113KB) AllocSpace objects, 15(110MB) LOS objects, 27% free, 62MB/86MB, paused 42us total 110.536ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 586(129KB) AllocSpace objects, 12(79MB) LOS objects, 23% free, 78MB/102MB, paused 5.330ms total 53.786ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 412(108KB) AllocSpace objects, 10(55MB) LOS objects, 0% free, 105MB/105MB, paused 5.299ms total 56.821ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 643(132KB) AllocSpace objects, 16(102MB) LOS objects, 22% free, 82MB/106MB, paused 6.610ms total 68.273ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 953(122KB) AllocSpace objects, 15(110MB) LOS objects, 24% free, 74MB/98MB, paused 8.114ms total 56.992ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 680(132KB) AllocSpace objects, 14(102MB) LOS objects, 21% free, 90MB/114MB, paused 5.048ms total 98.796ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 699(132KB) AllocSpace objects, 17(122MB) LOS objects, 17% free, 113MB/137MB, paused 8.216ms total 147.192ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 835(138KB) AllocSpace objects, 13(87MB) LOS objects, 18% free, 105MB/129MB, paused 5.110ms total 46.473ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 611(113KB) AllocSpace objects, 18(110MB) LOS objects, 18% free, 105MB/129MB, paused 9.029ms total 131.881ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 542(114KB) AllocSpace objects, 14(91MB) LOS objects, 22% free, 82MB/106MB, paused 1.943ms total 104.174ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 2026(172KB) AllocSpace objects, 6(31MB) LOS objects, 0% free, 121MB/121MB, paused 5.577ms total 45.898ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 932(122KB) AllocSpace objects, 18(126MB) LOS objects, 17% free, 113MB/137MB, paused 12.860ms total 157.656ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 615(138KB) AllocSpace objects, 12(79MB) LOS objects, 8% free, 90MB/98MB, paused 5.450ms total 49.171ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 402(123KB) AllocSpace objects, 9(47MB) LOS objects, 0% free, 90MB/90MB, paused 5.134ms total 43.901ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 545(129KB) AllocSpace objects, 13(87MB) LOS objects, 22% free, 82MB/106MB, paused 4.927ms total 101.877ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 1920(173KB) AllocSpace objects, 10(55MB) LOS objects, 0% free, 137MB/137MB, paused 6.196ms total 98.214ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1045(121KB) AllocSpace objects, 15(110MB) LOS objects, 21% free, 90MB/114MB, paused 15.813ms total 101.375ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 643(117KB) AllocSpace objects, 16(102MB) LOS objects, 21% free, 90MB/114MB, paused 5.194ms total 114.065ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 443(123KB) AllocSpace objects, 10(55MB) LOS objects, 7% free, 105MB/114MB, paused 5.368ms total 45.432ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 570(112KB) AllocSpace objects, 14(102MB) LOS objects, 21% free, 90MB/114MB, paused 16.813ms total 109.108ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 441(139KB) AllocSpace objects, 9(47MB) LOS objects, 0% free, 113MB/114MB, paused 5.350ms total 73.632ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 565(112KB) AllocSpace objects, 16(118MB) LOS objects, 21% free, 90MB/114MB, paused 15.614ms total 127.312ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 2755(233KB) AllocSpace objects, 22(134MB) LOS objects, 40% free, 34MB/58MB, paused 5.108ms total 199.667ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 641(123KB) AllocSpace objects, 12(79MB) LOS objects, 18% free, 86MB/106MB, paused 5.065ms total 42.161ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 495(112KB) AllocSpace objects, 16(102MB) LOS objects, 24% free, 74MB/98MB, paused 6.488ms total 91.346ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 405(108KB) AllocSpace objects, 9(47MB) LOS objects, 0% free, 105MB/105MB, paused 8.346ms total 47.287ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 468(123KB) AllocSpace objects, 10(55MB) LOS objects, 0% free, 105MB/106MB, paused 5.559ms total 42.262ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 555(112KB) AllocSpace objects, 14(102MB) LOS objects, 25% free, 70MB/94MB, paused 5.014ms total 56.909ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 354(107KB) AllocSpace objects, 9(47MB) LOS objects, 0% free, 113MB/113MB, paused 5.314ms total 75.680ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 401(114KB) AllocSpace objects, 15(110MB) LOS objects, 19% free, 98MB/122MB, paused 61us total 172.796ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 689(116KB) AllocSpace objects, 15(110MB) LOS objects, 22% free, 82MB/106MB, paused 4.191ms total 145.213ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 508(123KB) AllocSpace objects, 10(55MB) LOS objects, 0% free, 113MB/113MB, paused 5.743ms total 54.443ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 601(113KB) AllocSpace objects, 14(102MB) LOS objects, 19% free, 97MB/121MB, paused 77us total 143.185ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 602(112KB) AllocSpace objects, 16(110MB) LOS objects, 22% free, 82MB/106MB, paused 2.892ms total 125.388ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 2783(204KB) AllocSpace objects, 16(102MB) LOS objects, 21% free, 90MB/114MB, paused 8.590ms total 188.504ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 311(108KB) AllocSpace objects, 7(47MB) LOS objects, 7% free, 105MB/114MB, paused 170us total 111.434ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 680(128KB) AllocSpace objects, 17(110MB) LOS objects, 17% free, 113MB/137MB, paused 71.302ms total 936.910ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 934(153KB) AllocSpace objects, 20(118MB) LOS objects, 17% free, 113MB/137MB, paused 100us total 577.080ms
I/.cameraxexampl( 9964): Waiting for a blocking GC Alloc
I/.cameraxexampl( 9964): Background concurrent copying GC freed 3546(228KB) AllocSpace objects, 24(174MB) LOS objects, 23% free, 78MB/102MB, paused 28.002ms total 981.597ms
I/.cameraxexampl( 9964): WaitForGcToComplete blocked Alloc on HeapTrim for 520.767ms
I/.cameraxexampl( 9964): Starting a blocking GC Alloc
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 1295(149KB) AllocSpace objects, 18(110MB) LOS objects, 4% free, 98MB/102MB, paused 2.155ms total 180.011ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1196(156KB) AllocSpace objects, 15(110MB) LOS objects, 17% free, 113MB/137MB, paused 2.661ms total 152.778ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 835(122KB) AllocSpace objects, 13(87MB) LOS objects, 18% free, 105MB/129MB, paused 4.907ms total 146.448ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 2107(167KB) AllocSpace objects, 20(130MB) LOS objects, 19% free, 101MB/125MB, paused 3.264ms total 126.661ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 510(131KB) AllocSpace objects, 13(83MB) LOS objects, 0% free, 129MB/129MB, paused 3.289ms total 100.568ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 1128(139KB) AllocSpace objects, 13(87MB) LOS objects, 0% free, 113MB/113MB, paused 7.322ms total 114.670ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 805(146KB) AllocSpace objects, 18(126MB) LOS objects, 18% free, 105MB/129MB, paused 3.171ms total 187.321ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 1764(170KB) AllocSpace objects, 14(91MB) LOS objects, 20% free, 94MB/118MB, paused 6.835ms total 118.073ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 753(140KB) AllocSpace objects, 5(27MB) LOS objects, 0% free, 129MB/129MB, paused 5.253ms total 71.197ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1015(148KB) AllocSpace objects, 20(122MB) LOS objects, 17% free, 109MB/133MB, paused 4.563ms total 194.399ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1352(130KB) AllocSpace objects, 9(71MB) LOS objects, 20% free, 94MB/118MB, paused 6.294ms total 163.296ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 852(139KB) AllocSpace objects, 12(79MB) LOS objects, 13% free, 101MB/118MB, paused 14.387ms total 94.436ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1251(149KB) AllocSpace objects, 18(114MB) LOS objects, 19% free, 98MB/122MB, paused 533us total 293.696ms
I/.cameraxexampl( 9964): Background young concurrent copying GC freed 1599(167KB) AllocSpace objects, 13(87MB) LOS objects, 21% free, 90MB/114MB, paused 9.342ms total 210.376ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 1830(150KB) AllocSpace objects, 23(134MB) LOS objects, 32% free, 50MB/74MB, paused 9.046ms total 280.577ms
I/.cameraxexampl( 9964): Background concurrent copying GC freed 536(105KB) AllocSpace objects, 13(87MB) LOS objects, 22% free, 82MB/106MB, paused 108us total 281.084ms
Lost connection to device.
Failed to send request: {"jsonrpc":"2.0","id":"93","method":"getMemoryUsage","params":{"isolateId":"isolates/759871330662735"}} Turning on 04-01 11:22:52.605 540 540 E lowmemorykiller: [22875] 1000 17575 8447 0 com.coloros.deepthinker
04-01 11:22:52.605 540 540 E lowmemorykiller: [22898] 1000 17528 8539 0 com.heytap.mcs
04-01 11:22:52.605 540 540 E lowmemorykiller: [22869] 1000 17423 8509 0 com.oplus.crashbox
04-01 11:22:52.606 540 540 E lowmemorykiller: [22881] 10108 16690 8518 0 com.coloros.exserviceui
04-01 11:22:52.606 540 540 E lowmemorykiller: [22378] 10331 175398 324319 0 io.flutter.plugins.cameraxexample
04-01 11:22:52.606 540 540 E lowmemorykiller: [10650] 1000 3810 9719 0 com.coloros.securitypermission flutter doctor -v (stable and master)[✓] Flutter (Channel stable, 3.19.5, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.19.5 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 300451adae (25 hours ago), 2024-03-27 21:54:07 -0500
• Engine revision e76c956498
• Dart version 3.3.3
• DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C500b
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.87.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.84.0
[✓] Connected device (3 available)
• Pixel 7 (mobile) • 2B171FDH20084L • android-arm64 • Android 14 (API 34)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.86
[✓] Network resources
• All expected network resources are available.
• No issues found! [!] Flutter (Channel master, 3.22.0-1.0.pre.37, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.22.0-1.0.pre.37 on channel master at /Users/huynq/Documents/GitHub/flutter_master
! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision fd8561a917 (6 hours ago), 2024-03-31 17:12:24 -0400
• Engine revision 4f6b832c8e
• Dart version 3.5.0 (build 3.5.0-5.0.dev)
• DevTools version 2.34.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C500b
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.87.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.84.0
[✓] Connected device (3 available)
• iPad (mobile) • 00008103-000A1464346A201E • ios • iOS 17.2 21C62
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.87
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category. |
I ran the sample code and was able to see similar behavior* to that described in the memory profiler. I have two immediate thoughts:
*I see the memory greatly increasing but do not witness the crash. |
Hmm actually after reading https://developer.android.com/media/camera/camerax/analyze#operating-modes, I'm under the impression that using the default mode ( |
@jamesstevensdev Which devices did you notice this issue on? I edited my comment above, but I haven't actually seen the crash, so still working on reproducing and wondering if the device types are relevant. |
@camsim99 I have reproduced the crash on the Samsung A10, Google Pixel 4, and a Poco phone. However, occasionally, I noticed that the phone did not crash. The memory would spike to about 2GB and then drop back down. This was a rare occurrence. Most of the time, the phone would crash. Feel free to let me know if there is anything I can do to help reproduce this bug for you. I can send videos if needed. |
Thanks @jamesstevensdev! I tried this on a Pixel 3A and got the crash to repro and I see a lot more memory being used leading to the crash than I was able to repro with Pixel emulators (which don't crash). |
Took a look into this theory with @bparrishMines and he was able to point be more towards the cause: The To move forward here, I plan to play around with that time interval and at least briefly look into how we may be able to use Android's tools for managing memory to dynamically change the interval based on a suggestion by Maurice. @bparrishMines please feel free to add any context I missed! |
@camsim99 changing |
@gau-nernst Happy you were able to confirm that! I'm actively working on this, so yes. Likely in the next week or two. |
I've looked into:
Other than these, we know we can just lower the interval for the entire plugin. |
For solution 1, we would want to listen to the callback on the Java side. But since it seems to be supported by WidgetsBndingObserver, this solution would require changes to the engine. This callback is probably useful for plugins, but I think this would require a longer discussion about supporting it. For solution 2, the problem is not necessarily the number of instances in memory, but how much memory they take up. For image streaming, it looks like the objects stuck in memory were actually the I'm fine with implementing solution 3 since we already know that lowering the variable prevents the crash. You can also probably lower the default frequency to |
…ped native objects (#6493) This PR: 1. Shortens the `InstanceManager`'s default time interval that it waits to remove references to Dart-wrapped Android native objects. The shortened interval matches `webview_flutter_android`s `InstanceManager`; because it has been tested by that plugin, we expect it not to impact performance and this could help reduce overall memory usage by the plugin. 2. Dynamically shortens that same time interval whenever image streaming is started/stopped to account for the increased memory usage that this camera use case requires. Fixes flutter/flutter#145893.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to reproduce
pubspec.yaml
camera: ^0.10.5+9
camera_android_camerax: ^0.6.1
Expected results
Flutter should stream images and clean up the memory periodically.
Actual results
Memory continues to build up until the application crashes. Higher camera resolutions cause crashes much quicker. Occasionally, the memory profiler will show a drastic drop in memory usage before building up again.
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
Logs
Logs
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: