Repository navigation
Commit 456f992
authored
[camera_android_camerax] Fix leaked thread per capture in
Fixes flutter/flutter#190523
## Problem
`ImageCaptureProxyApi.takePicture` creates a new single-thread executor on
every call and never shuts it down. The thread it owns is only reclaimed
once its `FinalizableDelegatedExecutorService` wrapper is finalized, at a
time the plugin does not control.
That executor only delivers an already finished result — it does no real
work:
- Encoding and file I/O run on CameraX's own IO executor.
- `TakePictureRequest.onResult` does nothing but hand the result to the
executor the plugin passed in.
## Fix
Dispatch the result on the main executor instead, which is what this
plugin's other CameraX callbacks already use:
- `CameraControlProxyApi`
- `Camera2CameraControlProxyApi`
- `ImageAnalysisProxyApi`
- `ProcessCameraProviderProxyApi`
- `PendingRecordingProxyApi`
## Note
`PreviewProxyApi` uses the same per-request executor pattern for
`SurfaceRequest.provideSurface`. That callback releases a `Surface`, so it
is left for a separate change.
The two existing `takePicture` tests now stub the main executor on their
mock `Context`.
## Pre-Review ChecklisttakePicture (#12361)1 parent 2859366 commit 456f992
4 files changed
Lines changed: 45 additions & 3 deletions
File tree
- packages/camera/camera_android_camerax
- android/src
- main/java/io/flutter/plugins/camerax
- test/java/io/flutter/plugins/camerax
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
88 | 119 | | |
89 | 120 | | |
90 | 121 | | |
91 | 122 | | |
92 | 123 | | |
93 | 124 | | |
94 | 125 | | |
| 126 | + | |
| 127 | + | |
95 | 128 | | |
96 | 129 | | |
97 | 130 | | |
| |||
194 | 227 | | |
195 | 228 | | |
196 | 229 | | |
| 230 | + | |
| 231 | + | |
197 | 232 | | |
198 | 233 | | |
199 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments