software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.05k stars 1.31k forks source link

Memory leak on fresh bare react native + reanimated project #5614

Open DrRefactor opened 9 months ago

DrRefactor commented 9 months ago

Description

useSharedValue causes memory leak when component is rendered. I managed to create really simple minimal reproduction of a component that renders often and uses useSharedValue hook(s). The more often the component renders, the faster memory leaks.

Steps to reproduce

  1. Use useSharedValue (or render a few instances of this hook) inside component
  2. Add dummy useState with number type.
  3. Create interval that updates state frequently. Small intervals show the memory leaks really quick, slow intervals may require hours of waiting.

Snack or a link to a repository

repo

Reanimated version

3.6.2

React Native version

0.73.3

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Release app & production bundle

Device

Android emulator

Device model

Android TV emulator, android mobile emulator

Acknowledgements

Yes

DrRefactor commented 9 months ago

Please see repo readme on how to monitor memory usage conveniently.

DrRefactor commented 9 months ago

My repro app started using 130MB, reaching 430MB after an hour.

DrRefactor commented 9 months ago

Last ~30 minutes of logs from my monitor-memory.sh script:

[”15:57:55”]: peak memory: 252
253M    0:50.85
[”15:57:58”]: peak memory: 253
253M    0:51.06
[”15:58:01”]: peak memory: 253
254M    0:51.27
[”15:58:04”]: peak memory: 254
254M    0:51.46
[”15:58:07”]: peak memory: 254
255M    0:51.66
[”15:58:10”]: peak memory: 255
255M    0:51.86
[”15:58:13”]: peak memory: 255
255M    0:52.08
[”15:58:16”]: peak memory: 255
256M    0:52.28
[”15:58:19”]: peak memory: 256
256M    0:52.50
[”15:58:22”]: peak memory: 256
256M    0:52.73
[”15:58:25”]: peak memory: 256
257M    0:52.96
[”15:58:28”]: peak memory: 257
257M    0:53.22
[”15:58:31”]: peak memory: 257
258M    0:53.50
[”15:58:34”]: peak memory: 258
258M    0:53.72
[”15:58:37”]: peak memory: 258
259M    0:54.00
[”15:58:40”]: peak memory: 259
259M    0:54.24
[”15:58:43”]: peak memory: 259
260M    0:54.43
[”15:58:46”]: peak memory: 260
260M    0:54.69
[”15:58:49”]: peak memory: 260
260M    0:54.90
[”15:58:52”]: peak memory: 260
261M    0:55.19
[”15:58:55”]: peak memory: 261
261M    0:55.45
[”15:58:58”]: peak memory: 261
262M    0:55.68
[”15:59:01”]: peak memory: 262
262M    0:55.95
[”15:59:04”]: peak memory: 262
263M    0:56.13
[”15:59:07”]: peak memory: 263
263M    0:56.50
[”15:59:10”]: peak memory: 263
263M    0:56.76
[”15:59:13”]: peak memory: 263
264M    0:56.97
[”15:59:16”]: peak memory: 264
264M    0:57.17
[”15:59:19”]: peak memory: 264
264M    0:57.39
[”15:59:22”]: peak memory: 264
265M    0:57.62
[”15:59:25”]: peak memory: 265
265M    0:57.82
[”15:59:28”]: peak memory: 265
266M    0:58.02
[”15:59:31”]: peak memory: 266
278M    0:58.30
[”15:59:34”]: peak memory: 278
278M    0:58.50
[”15:59:37”]: peak memory: 278
279M    0:58.72
[”15:59:40”]: peak memory: 279
279M    0:58.92
[”15:59:43”]: peak memory: 279
279M    0:59.11
[”15:59:46”]: peak memory: 279
280M    0:59.35
[”15:59:49”]: peak memory: 280
280M    0:59.55
[”15:59:52”]: peak memory: 280
281M    0:59.78
[”15:59:55”]: peak memory: 281
281M    0:59.99
[”15:59:58”]: peak memory: 281
281M    1:00.25
[”16:00:01”]: peak memory: 281
282M    1:00.45
[”16:00:04”]: peak memory: 282
282M    1:00.68
[”16:00:07”]: peak memory: 282
282M    1:00.95
[”16:00:10”]: peak memory: 282
283M    1:01.16
[”16:00:13”]: peak memory: 283
283M    1:01.37
[”16:00:16”]: peak memory: 283
284M    1:01.61
[”16:00:19”]: peak memory: 284
284M    1:01.83
[”16:00:22”]: peak memory: 284
285M    1:02.03
[”16:00:25”]: peak memory: 285
285M    1:02.22
[”16:00:28”]: peak memory: 285
285M    1:02.42
[”16:00:31”]: peak memory: 285
286M    1:02.64
[”16:00:34”]: peak memory: 286
286M    1:02.83
[”16:00:37”]: peak memory: 286
287M    1:03.05
[”16:00:40”]: peak memory: 287
287M    1:03.24
[”16:00:43”]: peak memory: 287
287M    1:03.45
[”16:00:46”]: peak memory: 287
288M    1:03.65
[”16:00:49”]: peak memory: 288
288M    1:03.88
[”16:00:52”]: peak memory: 288
289M    1:04.08
[”16:00:55”]: peak memory: 289
289M    1:04.28
[”16:00:58”]: peak memory: 289
289M    1:04.48
[”16:01:01”]: peak memory: 289
290M    1:04.68
[”16:01:04”]: peak memory: 290
290M    1:04.85
[”16:01:07”]: peak memory: 290
291M    1:05.07
[”16:01:10”]: peak memory: 291
291M    1:05.26
[”16:01:13”]: peak memory: 291
291M    1:05.46
[”16:01:16”]: peak memory: 291
292M    1:05.65
[”16:01:19”]: peak memory: 292
292M    1:05.84
[”16:01:22”]: peak memory: 292
293M    1:06.03
[”16:01:25”]: peak memory: 293
293M    1:06.23
[”16:01:28”]: peak memory: 293
294M    1:06.42
[”16:01:31”]: peak memory: 294
294M    1:06.65
[”16:01:34”]: peak memory: 294
294M    1:06.83
[”16:01:37”]: peak memory: 294
295M    1:07.03
[”16:01:40”]: peak memory: 295
295M    1:07.26
[”16:01:43”]: peak memory: 295
296M    1:07.48
[”16:01:46”]: peak memory: 296
296M    1:07.73
[”16:01:49”]: peak memory: 296
296M    1:07.96
[”16:01:52”]: peak memory: 296
297M    1:08.22
[”16:01:55”]: peak memory: 297
297M    1:08.43
[”16:01:58”]: peak memory: 297
298M    1:08.68
[”16:02:01”]: peak memory: 298
298M    1:08.88
[”16:02:04”]: peak memory: 298
298M    1:09.08
[”16:02:07”]: peak memory: 298
299M    1:09.29
[”16:02:10”]: peak memory: 299
299M    1:09.48
[”16:02:13”]: peak memory: 299
300M    1:09.69
[”16:02:16”]: peak memory: 300
300M    1:09.88
[”16:02:19”]: peak memory: 300
301M    1:10.11
[”16:02:22”]: peak memory: 301
301M    1:10.34
[”16:02:25”]: peak memory: 301
301M    1:10.57
[”16:02:28”]: peak memory: 301
301M    1:10.77
[”16:02:31”]: peak memory: 301
302M    1:11.01
[”16:02:34”]: peak memory: 302
302M    1:11.21
[”16:02:37”]: peak memory: 302
303M    1:11.42
[”16:02:40”]: peak memory: 303
303M    1:11.63
[”16:02:43”]: peak memory: 303
303M    1:11.82
[”16:02:46”]: peak memory: 303
304M    1:12.03
[”16:02:49”]: peak memory: 304
304M    1:12.24
[”16:02:52”]: peak memory: 304
305M    1:12.45
[”16:02:55”]: peak memory: 305
305M    1:12.66
[”16:02:58”]: peak memory: 305
306M    1:12.85
[”16:03:01”]: peak memory: 306
306M    1:13.06
[”16:03:04”]: peak memory: 306
306M    1:13.27
[”16:03:07”]: peak memory: 306
307M    1:13.45
[”16:03:10”]: peak memory: 307
307M    1:13.67
[”16:03:13”]: peak memory: 307
308M    1:13.88
[”16:03:16”]: peak memory: 308
308M    1:14.09
[”16:03:19”]: peak memory: 308
308M    1:14.28
[”16:03:22”]: peak memory: 308
309M    1:14.53
[”16:03:25”]: peak memory: 309
309M    1:14.81
[”16:03:28”]: peak memory: 309
310M    1:15.04
[”16:03:31”]: peak memory: 310
310M    1:15.29
[”16:03:34”]: peak memory: 310
310M    1:15.51
[”16:03:37”]: peak memory: 310
311M    1:15.69
[”16:03:40”]: peak memory: 311
311M    1:15.91
[”16:03:43”]: peak memory: 311
311M    1:16.14
[”16:03:46”]: peak memory: 311
312M    1:16.36
[”16:03:49”]: peak memory: 312
312M    1:16.64
[”16:03:52”]: peak memory: 312
313M    1:16.87
[”16:03:55”]: peak memory: 313
313M    1:17.09
[”16:03:58”]: peak memory: 313
314M    1:17.37
[”16:04:01”]: peak memory: 314
314M    1:17.59
[”16:04:04”]: peak memory: 314
319M    1:17.91
[”16:04:07”]: peak memory: 319
319M    1:18.18
[”16:04:10”]: peak memory: 319
319M    1:18.41
[”16:04:13”]: peak memory: 319
320M    1:18.63
[”16:04:16”]: peak memory: 320
320M    1:18.83
[”16:04:19”]: peak memory: 320
321M    1:19.06
[”16:04:22”]: peak memory: 321
321M    1:19.35
[”16:04:25”]: peak memory: 321
322M    1:19.62
[”16:04:28”]: peak memory: 322
322M    1:19.90
[”16:04:31”]: peak memory: 322
322M    1:20.12
[”16:04:34”]: peak memory: 322
323M    1:20.41
[”16:04:37”]: peak memory: 323
323M    1:20.61
[”16:04:40”]: peak memory: 323
324M    1:20.83
[”16:04:43”]: peak memory: 324
324M    1:21.03
[”16:04:46”]: peak memory: 324
324M    1:21.23
[”16:04:49”]: peak memory: 324
325M    1:21.46
[”16:04:52”]: peak memory: 325
325M    1:21.66
[”16:04:55”]: peak memory: 325
326M    1:21.93
[”16:04:58”]: peak memory: 326
326M    1:22.17
[”16:05:01”]: peak memory: 326
326M    1:22.37
[”16:05:04”]: peak memory: 326
327M    1:22.58
[”16:05:07”]: peak memory: 327
327M    1:22.89
[”16:05:10”]: peak memory: 327
328M    1:23.09
[”16:05:13”]: peak memory: 328
328M    1:23.37
[”16:05:16”]: peak memory: 328
329M    1:23.61
[”16:05:19”]: peak memory: 329
329M    1:23.87
[”16:05:22”]: peak memory: 329
329M    1:24.11
[”16:05:25”]: peak memory: 329
330M    1:24.31
[”16:05:28”]: peak memory: 330
330M    1:24.49
[”16:05:31”]: peak memory: 330
331M    1:24.72
[”16:05:34”]: peak memory: 331
329M    1:24.96
[”16:05:37”]: peak memory: 331
330M    1:25.18
[”16:05:40”]: peak memory: 331
330M    1:25.40
[”16:05:43”]: peak memory: 331
330M    1:25.65
[”16:05:46”]: peak memory: 331
331M    1:25.87
[”16:05:50”]: peak memory: 331
331M    1:26.08
[”16:05:53”]: peak memory: 331
332M    1:26.29
[”16:05:56”]: peak memory: 332
332M    1:26.53
[”16:05:59”]: peak memory: 332
332M    1:26.74
[”16:06:02”]: peak memory: 332
333M    1:27.01
[”16:06:05”]: peak memory: 333
333M    1:27.23
[”16:06:08”]: peak memory: 333
333M    1:27.56
[”16:06:11”]: peak memory: 333
334M    1:27.80
[”16:06:14”]: peak memory: 334
334M    1:28.03
[”16:06:17”]: peak memory: 334
335M    1:28.37
[”16:06:20”]: peak memory: 335
335M    1:28.57
[”16:06:23”]: peak memory: 335
336M    1:28.78
[”16:06:26”]: peak memory: 336
336M    1:29.01
[”16:06:29”]: peak memory: 336
337M    1:29.20
[”16:06:32”]: peak memory: 337
337M    1:29.42
[”16:06:35”]: peak memory: 337
337M    1:29.64
[”16:06:38”]: peak memory: 337
338M    1:29.86
[”16:06:41”]: peak memory: 338
338M    1:30.06
[”16:06:44”]: peak memory: 338
338M    1:30.25
[”16:06:47”]: peak memory: 338
339M    1:30.49
[”16:06:50”]: peak memory: 339
339M    1:30.71
[”16:06:53”]: peak memory: 339
340M    1:30.92
[”16:06:56”]: peak memory: 340
340M    1:31.13
[”16:06:59”]: peak memory: 340
341M    1:31.37
[”16:07:02”]: peak memory: 341
341M    1:31.57
[”16:07:05”]: peak memory: 341
341M    1:31.79
[”16:07:08”]: peak memory: 341
342M    1:32.00
[”16:07:11”]: peak memory: 342
342M    1:32.21
[”16:07:14”]: peak memory: 342
342M    1:32.43
[”16:07:17”]: peak memory: 342
343M    1:32.73
[”16:07:20”]: peak memory: 343
343M    1:32.94
[”16:07:23”]: peak memory: 343
344M    1:33.16
[”16:07:26”]: peak memory: 344
344M    1:33.40
[”16:07:29”]: peak memory: 344
345M    1:33.62
[”16:07:32”]: peak memory: 345
345M    1:33.88
[”16:07:35”]: peak memory: 345
345M    1:34.12
[”16:07:38”]: peak memory: 345
346M    1:34.34
[”16:07:41”]: peak memory: 346
346M    1:34.58
[”16:07:44”]: peak memory: 346
346M    1:34.80
[”16:07:47”]: peak memory: 346
347M    1:35.06
[”16:07:50”]: peak memory: 347
347M    1:35.31
[”16:07:53”]: peak memory: 347
348M    1:35.51
[”16:07:56”]: peak memory: 348
348M    1:35.79
[”16:07:59”]: peak memory: 348
349M    1:36.02
[”16:08:02”]: peak memory: 349
349M    1:36.27
[”16:08:05”]: peak memory: 349
350M    1:36.48
[”16:08:08”]: peak memory: 350
350M    1:36.72
[”16:08:11”]: peak memory: 350
350M    1:37.01
[”16:08:14”]: peak memory: 350
351M    1:37.24
[”16:08:17”]: peak memory: 351
351M    1:37.44
[”16:08:20”]: peak memory: 351
352M    1:37.62
[”16:08:23”]: peak memory: 352
352M    1:37.82
[”16:08:26”]: peak memory: 352
352M    1:38.07
[”16:08:29”]: peak memory: 352
352M    1:38.31
[”16:08:32”]: peak memory: 352
353M    1:38.55
[”16:08:35”]: peak memory: 353
353M    1:38.77
[”16:08:38”]: peak memory: 353
354M    1:38.97
[”16:08:41”]: peak memory: 354
354M    1:39.18
[”16:08:44”]: peak memory: 354
354M    1:39.41
[”16:08:47”]: peak memory: 354
355M    1:39.60
[”16:08:50”]: peak memory: 355
355M    1:39.81
[”16:08:53”]: peak memory: 355
356M    1:40.03
[”16:08:56”]: peak memory: 356
356M    1:40.28
[”16:08:59”]: peak memory: 356
356M    1:40.50
[”16:09:02”]: peak memory: 356
357M    1:40.74
[”16:09:05”]: peak memory: 357
357M    1:40.98
[”16:09:08”]: peak memory: 357
358M    1:41.20
[”16:09:11”]: peak memory: 358
358M    1:41.43
[”16:09:14”]: peak memory: 358
359M    1:41.64
[”16:09:17”]: peak memory: 359
359M    1:41.88
[”16:09:20”]: peak memory: 359
359M    1:42.13
[”16:09:23”]: peak memory: 359
360M    1:42.34
[”16:09:26”]: peak memory: 360
360M    1:42.59
[”16:09:29”]: peak memory: 360
360M    1:42.84
[”16:09:32”]: peak memory: 360
361M    1:43.04
[”16:09:35”]: peak memory: 361
361M    1:43.26
[”16:09:38”]: peak memory: 361
362M    1:43.47
[”16:09:41”]: peak memory: 362
362M    1:43.72
[”16:09:44”]: peak memory: 362
363M    1:43.94
[”16:09:47”]: peak memory: 363
363M    1:44.19
[”16:09:50”]: peak memory: 363
363M    1:44.41
[”16:09:53”]: peak memory: 363
364M    1:44.62
[”16:09:56”]: peak memory: 364
364M    1:44.85
[”16:09:59”]: peak memory: 364
365M    1:45.09
[”16:10:02”]: peak memory: 365
365M    1:45.32
[”16:10:05”]: peak memory: 365
365M    1:45.50
[”16:10:08”]: peak memory: 365
366M    1:45.79
[”16:10:11”]: peak memory: 366
366M    1:46.01
[”16:10:14”]: peak memory: 366
367M    1:46.21
[”16:10:17”]: peak memory: 367
367M    1:46.45
[”16:10:20”]: peak memory: 367
367M    1:46.66
[”16:10:23”]: peak memory: 367
368M    1:46.88
[”16:10:26”]: peak memory: 368
368M    1:47.10
[”16:10:29”]: peak memory: 368
369M    1:47.35
[”16:10:32”]: peak memory: 369
369M    1:47.56
[”16:10:35”]: peak memory: 369
370M    1:47.77
[”16:10:38”]: peak memory: 370
370M    1:47.96
[”16:10:41”]: peak memory: 370
370M    1:48.17
[”16:10:44”]: peak memory: 370
371M    1:48.40
[”16:10:47”]: peak memory: 371
371M    1:48.58
[”16:10:50”]: peak memory: 371
372M    1:48.80
[”16:10:53”]: peak memory: 372
372M    1:49.04
[”16:10:56”]: peak memory: 372
372M    1:49.26
[”16:10:59”]: peak memory: 372
376M    1:49.53
[”16:11:02”]: peak memory: 376
375M    1:49.84
[”16:11:05”]: peak memory: 376
375M    1:50.08
[”16:11:08”]: peak memory: 376
375M    1:50.33
[”16:11:11”]: peak memory: 376
376M    1:50.56
[”16:11:14”]: peak memory: 376
376M    1:50.81
[”16:11:17”]: peak memory: 376
376M    1:50.99
[”16:11:20”]: peak memory: 376
377M    1:51.22
[”16:11:23”]: peak memory: 377
377M    1:51.43
[”16:11:26”]: peak memory: 377
378M    1:51.65
[”16:11:29”]: peak memory: 378
378M    1:51.90
[”16:11:32”]: peak memory: 378
378M    1:52.13
[”16:11:35”]: peak memory: 378
379M    1:52.33
[”16:11:38”]: peak memory: 379
379M    1:52.56
[”16:11:41”]: peak memory: 379
379M    1:52.80
[”16:11:44”]: peak memory: 379
372M    1:53.04
[”16:11:47”]: peak memory: 379
373M    1:53.24
[”16:11:50”]: peak memory: 379
373M    1:53.50
[”16:11:53”]: peak memory: 379
373M    1:53.75
[”16:11:56”]: peak memory: 379
374M    1:53.98
[”16:11:59”]: peak memory: 379
374M    1:54.22
[”16:12:02”]: peak memory: 379
375M    1:54.44
[”16:12:05”]: peak memory: 379
375M    1:54.73
[”16:12:08”]: peak memory: 379
375M    1:54.95
[”16:12:11”]: peak memory: 379
376M    1:55.27
[”16:12:14”]: peak memory: 379
376M    1:55.56
[”16:12:17”]: peak memory: 379
376M    1:55.82
[”16:12:20”]: peak memory: 379
377M    1:56.07
[”16:12:23”]: peak memory: 379
377M    1:56.30
[”16:12:26”]: peak memory: 379
378M    1:56.53
[”16:12:29”]: peak memory: 379
378M    1:56.77
[”16:12:32”]: peak memory: 379
378M    1:56.99
[”16:12:35”]: peak memory: 379
379M    1:57.24
[”16:12:38”]: peak memory: 379
379M    1:57.45
[”16:12:41”]: peak memory: 379
379M    1:57.71
[”16:12:44”]: peak memory: 379
380M    1:57.93
[”16:12:47”]: peak memory: 380
380M    1:58.16
[”16:12:50”]: peak memory: 380
380M    1:58.37
[”16:12:53”]: peak memory: 380
381M    1:58.59
[”16:12:56”]: peak memory: 381
381M    1:58.80
[”16:12:59”]: peak memory: 381
382M    1:59.03
[”16:13:02”]: peak memory: 382
382M    1:59.25
[”16:13:05”]: peak memory: 382
382M    1:59.46
[”16:13:08”]: peak memory: 382
383M    1:59.70
[”16:13:11”]: peak memory: 383
383M    1:59.93
[”16:13:14”]: peak memory: 383
384M    2:00.16
[”16:13:17”]: peak memory: 384
384M    2:00.38
[”16:13:20”]: peak memory: 384
385M    2:00.60
[”16:13:23”]: peak memory: 385
385M    2:00.84
[”16:13:26”]: peak memory: 385
385M    2:01.08
[”16:13:29”]: peak memory: 385
386M    2:01.27
[”16:13:32”]: peak memory: 386
381M    2:01.53
[”16:13:35”]: peak memory: 386
382M    2:01.79
[”16:13:38”]: peak memory: 386
382M    2:02.06
[”16:13:41”]: peak memory: 386
382M    2:02.35
[”16:13:44”]: peak memory: 386
383M    2:02.55
[”16:13:47”]: peak memory: 386
383M    2:02.79
[”16:13:50”]: peak memory: 386
383M    2:03.00
[”16:13:53”]: peak memory: 386
384M    2:03.23
[”16:13:56”]: peak memory: 386
384M    2:03.47
[”16:13:59”]: peak memory: 386
385M    2:03.69
[”16:14:02”]: peak memory: 386
385M    2:03.92
[”16:14:05”]: peak memory: 386
385M    2:04.11
[”16:14:08”]: peak memory: 386
386M    2:04.34
[”16:14:11”]: peak memory: 386
386M    2:04.57
[”16:14:14”]: peak memory: 386
386M    2:04.79
[”16:14:17”]: peak memory: 386
387M    2:05.03
[”16:14:20”]: peak memory: 387
387M    2:05.27
[”16:14:23”]: peak memory: 387
388M    2:05.52
[”16:14:26”]: peak memory: 388
388M    2:05.74
[”16:14:29”]: peak memory: 388
388M    2:05.99
[”16:14:32”]: peak memory: 388
389M    2:06.23
[”16:14:35”]: peak memory: 389
389M    2:06.44
[”16:14:38”]: peak memory: 389
389M    2:06.68
[”16:14:41”]: peak memory: 389
390M    2:06.91
[”16:14:44”]: peak memory: 390
391M    2:07.16
[”16:14:47”]: peak memory: 391
391M    2:07.39
[”16:14:50”]: peak memory: 391
391M    2:07.64
[”16:14:53”]: peak memory: 391
392M    2:07.88
[”16:14:56”]: peak memory: 392
392M    2:08.10
[”16:14:59”]: peak memory: 392
393M    2:08.35
[”16:15:02”]: peak memory: 393
393M    2:08.58
[”16:15:05”]: peak memory: 393
393M    2:08.84
[”16:15:08”]: peak memory: 393
394M    2:09.05
[”16:15:11”]: peak memory: 394
394M    2:09.30
[”16:15:14”]: peak memory: 394
394M    2:09.53
[”16:15:17”]: peak memory: 394
395M    2:09.74
[”16:15:20”]: peak memory: 395
395M    2:09.98
[”16:15:23”]: peak memory: 395
396M    2:10.21
[”16:15:26”]: peak memory: 396
396M    2:10.45
[”16:15:29”]: peak memory: 396
397M    2:10.66
[”16:15:32”]: peak memory: 397
397M    2:10.93
[”16:15:35”]: peak memory: 397
397M    2:11.14
[”16:15:38”]: peak memory: 397
398M    2:11.36
[”16:15:41”]: peak memory: 398
398M    2:11.60
[”16:15:44”]: peak memory: 398
398M    2:11.83
[”16:15:47”]: peak memory: 398
399M    2:12.05
[”16:15:50”]: peak memory: 399
399M    2:12.30
[”16:15:53”]: peak memory: 399
400M    2:12.55
[”16:15:56”]: peak memory: 400
400M    2:12.77
[”16:15:59”]: peak memory: 400
401M    2:13.03
[”16:16:02”]: peak memory: 401
401M    2:13.27
[”16:16:05”]: peak memory: 401
401M    2:13.52
[”16:16:08”]: peak memory: 401
397M    2:13.75
[”16:16:11”]: peak memory: 401
398M    2:14.02
[”16:16:14”]: peak memory: 401
398M    2:14.28
[”16:16:17”]: peak memory: 401
399M    2:14.50
[”16:16:20”]: peak memory: 401
399M    2:14.81
[”16:16:23”]: peak memory: 401
399M    2:15.04
[”16:16:26”]: peak memory: 401
400M    2:15.26
[”16:16:29”]: peak memory: 401
400M    2:15.55
[”16:16:32”]: peak memory: 401
400M    2:15.86
[”16:16:35”]: peak memory: 401
401M    2:16.12
[”16:16:38”]: peak memory: 401
401M    2:16.41
[”16:16:41”]: peak memory: 401
402M    2:16.72
[”16:16:44”]: peak memory: 402
402M    2:17.02
[”16:16:47”]: peak memory: 402
403M    2:17.30
[”16:16:50”]: peak memory: 403
403M    2:17.61
[”16:16:53”]: peak memory: 403
403M    2:17.86
[”16:16:56”]: peak memory: 403
404M    2:18.12
[”16:16:59”]: peak memory: 404
404M    2:18.37
[”16:17:02”]: peak memory: 404
405M    2:18.64
[”16:17:05”]: peak memory: 405
405M    2:18.88
[”16:17:08”]: peak memory: 405
405M    2:19.10
[”16:17:11”]: peak memory: 405
406M    2:19.37
[”16:17:14”]: peak memory: 406
406M    2:19.61
[”16:17:17”]: peak memory: 406
407M    2:19.86
[”16:17:20”]: peak memory: 407
407M    2:20.12
[”16:17:23”]: peak memory: 407
407M    2:20.37
[”16:17:26”]: peak memory: 407
408M    2:20.63
[”16:17:29”]: peak memory: 408
408M    2:20.88
[”16:17:32”]: peak memory: 408
409M    2:21.18
[”16:17:35”]: peak memory: 409
409M    2:21.42
[”16:17:38”]: peak memory: 409
410M    2:21.69
[”16:17:41”]: peak memory: 410
410M    2:21.93
[”16:17:44”]: peak memory: 410
410M    2:22.20
[”16:17:47”]: peak memory: 410
411M    2:22.49
[”16:17:50”]: peak memory: 411
411M    2:22.70
[”16:17:53”]: peak memory: 411
411M    2:22.94
[”16:17:56”]: peak memory: 411
412M    2:23.18
[”16:17:59”]: peak memory: 412
412M    2:23.44
[”16:18:02”]: peak memory: 412
413M    2:23.67
[”16:18:05”]: peak memory: 413
413M    2:23.98
[”16:18:08”]: peak memory: 413
414M    2:24.20
[”16:18:11”]: peak memory: 414
414M    2:24.43
[”16:18:14”]: peak memory: 414
414M    2:24.68
[”16:18:17”]: peak memory: 414
415M    2:24.90
[”16:18:20”]: peak memory: 415
415M    2:25.13
[”16:18:23”]: peak memory: 415
416M    2:25.42
[”16:18:26”]: peak memory: 416
414M    2:25.65
[”16:18:29”]: peak memory: 416
414M    2:25.95
[”16:18:32”]: peak memory: 416
415M    2:26.23
[”16:18:35”]: peak memory: 416
415M    2:26.48
[”16:18:38”]: peak memory: 416
416M    2:26.71
[”16:18:41”]: peak memory: 416
416M    2:27.02
[”16:18:44”]: peak memory: 416
416M    2:27.29
[”16:18:47”]: peak memory: 416
417M    2:27.52
[”16:18:50”]: peak memory: 417
417M    2:27.77
[”16:18:53”]: peak memory: 417
418M    2:28.00
[”16:18:56”]: peak memory: 418
418M    2:28.26
[”16:18:59”]: peak memory: 418
418M    2:28.47
[”16:19:02”]: peak memory: 418
419M    2:28.73
[”16:19:05”]: peak memory: 419
419M    2:28.99
[”16:19:08”]: peak memory: 419
420M    2:29.20
[”16:19:11”]: peak memory: 420
420M    2:29.44
[”16:19:14”]: peak memory: 420
421M    2:29.66
[”16:19:17”]: peak memory: 421
421M    2:29.91
[”16:19:20”]: peak memory: 421
421M    2:30.15
[”16:19:23”]: peak memory: 421
422M    2:30.38
[”16:19:26”]: peak memory: 422
422M    2:30.60
[”16:19:29”]: peak memory: 422
423M    2:30.84
[”16:19:32”]: peak memory: 423
423M    2:31.13
[”16:19:35”]: peak memory: 423
423M    2:31.42
[”16:19:38”]: peak memory: 423
424M    2:31.70
[”16:19:41”]: peak memory: 424
424M    2:31.95
[”16:19:44”]: peak memory: 424
425M    2:32.26
[”16:19:47”]: peak memory: 425
425M    2:32.56
[”16:19:50”]: peak memory: 425
426M    2:32.84
[”16:19:53”]: peak memory: 426
426M    2:33.16
[”16:19:56”]: peak memory: 426
426M    2:33.44
[”16:19:59”]: peak memory: 426
427M    2:33.75
[”16:20:02”]: peak memory: 427
427M    2:34.03
[”16:20:05”]: peak memory: 427
428M    2:34.26
[”16:20:08”]: peak memory: 428
428M    2:34.51
[”16:20:11”]: peak memory: 428
428M    2:34.74
[”16:20:14”]: peak memory: 428
429M    2:34.98
[”16:20:17”]: peak memory: 429
429M    2:35.27
[”16:20:20”]: peak memory: 429
430M    2:35.53
[”16:20:23”]: peak memory: 430
430M    2:35.75
[”16:20:26”]: peak memory: 430
431M    2:36.00
[”16:20:29”]: peak memory: 431
431M    2:36.23
[”16:20:32”]: peak memory: 431
431M    2:36.45
[”16:20:35”]: peak memory: 431
432M    2:36.72
[”16:20:38”]: peak memory: 432
432M    2:36.97
[”16:20:41”]: peak memory: 432
433M    2:37.25
[”16:20:44”]: peak memory: 433
433M    2:37.51
[”16:20:47”]: peak memory: 433
433M    2:37.82
[”16:20:50”]: peak memory: 433
434M    2:38.09
[”16:20:53”]: peak memory: 434
431M    2:38.34
[”16:20:56”]: peak memory: 434
432M    2:38.61
[”16:20:59”]: peak memory: 434
432M    2:38.85
[”16:21:02”]: peak memory: 434
433M    2:39.10
[”16:21:05”]: peak memory: 434
433M    2:39.34
[”16:21:08”]: peak memory: 434
433M    2:39.58
[”16:21:11”]: peak memory: 434
434M    2:39.84
[”16:21:14”]: peak memory: 434
434M    2:40.07
[”16:21:17”]: peak memory: 434
434M    2:40.34
[”16:21:20”]: peak memory: 434
435M    2:40.56
[”16:21:23”]: peak memory: 435
436M    2:40.76
[”16:21:26”]: peak memory: 436
436M    2:40.99
[”16:21:29”]: peak memory: 436
436M    2:41.27
[”16:21:32”]: peak memory: 436
437M    2:41.53
[”16:21:35”]: peak memory: 437
437M    2:41.78
[”16:21:38”]: peak memory: 437
438M    2:42.01
[”16:21:41”]: peak memory: 438
438M    2:42.25
[”16:21:44”]: peak memory: 438
438M    2:42.47
[”16:21:47”]: peak memory: 438
439M    2:42.72
[”16:21:50”]: peak memory: 439
439M    2:42.96
[”16:21:53”]: peak memory: 439
440M    2:43.21
[”16:21:56”]: peak memory: 440
440M    2:43.42
[”16:21:59”]: peak memory: 440
440M    2:43.66
[”16:22:02”]: peak memory: 440
441M    2:43.88
[”16:22:05”]: peak memory: 441
441M    2:44.14
[”16:22:08”]: peak memory: 441
442M    2:44.38
[”16:22:11”]: peak memory: 442
442M    2:44.64
[”16:22:14”]: peak memory: 442
442M    2:44.90
[”16:22:17”]: peak memory: 442
443M    2:45.17
[”16:22:20”]: peak memory: 443
444M    2:45.47
[”16:22:23”]: peak memory: 444
444M    2:45.71
[”16:22:26”]: peak memory: 444
444M    2:45.94
[”16:22:29”]: peak memory: 444
444M    2:46.25
[”16:22:32”]: peak memory: 444
445M    2:46.50
[”16:22:35”]: peak memory: 445
445M    2:46.77
[”16:22:38”]: peak memory: 445
446M    2:46.97
[”16:22:41”]: peak memory: 446
446M    2:47.21
[”16:22:44”]: peak memory: 446
446M    2:47.46
[”16:22:47”]: peak memory: 446
447M    2:47.67
[”16:22:50”]: peak memory: 447
447M    2:47.91
[”16:22:53”]: peak memory: 447
448M    2:48.17
[”16:22:56”]: peak memory: 448
448M    2:48.48
[”16:22:59”]: peak memory: 448
449M    2:48.75
[”16:23:02”]: peak memory: 449
449M    2:49.02
[”16:23:05”]: peak memory: 449
434M    2:49.24
[”16:23:08”]: peak memory: 449
434M    2:49.55
[”16:23:11”]: peak memory: 449
435M    2:49.85
[”16:23:14”]: peak memory: 449
435M    2:50.12
[”16:23:17”]: peak memory: 449
436M    2:50.40
[”16:23:20”]: peak memory: 449
436M    2:50.65
[”16:23:23”]: peak memory: 449
ranaavneet commented 9 months ago

Could you try it with latest nightly build and see if it still happens?

DrRefactor commented 9 months ago

Started testing, will let you know in a while. I've had some problems to compile with nightly build, so I created PR with potential fix (just for an app build): https://github.com/software-mansion/react-native-reanimated/pull/5615

DrRefactor commented 9 months ago

It looks really promising, memory did rise up a bit, but GC's done its job after some time, and memory is kept in check since. It's been about 40 minutes, and memory cycles between 150~180MB. Some recent logs:

[”20:27:10”]: peak memory: 167
167M    1:40.47
[”20:27:13”]: peak memory: 167
167M    1:40.64
[”20:27:16”]: peak memory: 167
167M    1:40.80
[”20:27:19”]: peak memory: 167
168M    1:40.98
[”20:27:22”]: peak memory: 168
168M    1:41.14
[”20:27:25”]: peak memory: 168
168M    1:41.30
[”20:27:28”]: peak memory: 168
168M    1:41.47
[”20:27:31”]: peak memory: 168
168M    1:41.61
[”20:27:34”]: peak memory: 168
168M    1:41.73
[”20:27:37”]: peak memory: 168
168M    1:41.85
[”20:27:40”]: peak memory: 168
168M    1:42.01
[”20:27:43”]: peak memory: 168
168M    1:42.17
[”20:27:46”]: peak memory: 168
168M    1:42.31
[”20:27:49”]: peak memory: 168
168M    1:42.49
[”20:27:52”]: peak memory: 168
168M    1:42.65
[”20:27:55”]: peak memory: 168
168M    1:42.81
[”20:27:58”]: peak memory: 168
168M    1:42.98
[”20:28:01”]: peak memory: 168
168M    1:43.13
[”20:28:04”]: peak memory: 168
168M    1:43.29
[”20:28:07”]: peak memory: 168
168M    1:43.44
[”20:28:10”]: peak memory: 168
168M    1:43.61
[”20:28:13”]: peak memory: 168
168M    1:43.75
[”20:28:16”]: peak memory: 168
168M    1:43.87
[”20:28:19”]: peak memory: 168
168M    1:44.00
[”20:28:22”]: peak memory: 168
168M    1:44.17
[”20:28:25”]: peak memory: 168
169M    1:44.33
[”20:28:28”]: peak memory: 169
169M    1:44.50
[”20:28:31”]: peak memory: 169
169M    1:44.65
[”20:28:34”]: peak memory: 169
169M    1:44.81
[”20:28:37”]: peak memory: 169
169M    1:44.95
[”20:28:40”]: peak memory: 169
169M    1:45.05
[”20:28:43”]: peak memory: 169
169M    1:45.17
[”20:28:46”]: peak memory: 169
169M    1:45.29
[”20:28:49”]: peak memory: 169
169M    1:45.40
[”20:28:52”]: peak memory: 169
169M    1:45.52
[”20:28:55”]: peak memory: 169
169M    1:45.64
[”20:28:58”]: peak memory: 169
169M    1:45.75
[”20:29:01”]: peak memory: 169
169M    1:45.87
[”20:29:04”]: peak memory: 169
169M    1:45.99
[”20:29:07”]: peak memory: 169
169M    1:46.11
[”20:29:10”]: peak memory: 169
169M    1:46.24
[”20:29:13”]: peak memory: 169
169M    1:46.36
[”20:29:16”]: peak memory: 169
169M    1:46.48
[”20:29:19”]: peak memory: 169
169M    1:46.60
[”20:29:22”]: peak memory: 169
170M    1:46.72
[”20:29:25”]: peak memory: 170
170M    1:46.83
[”20:29:28”]: peak memory: 170
170M    1:46.96
[”20:29:31”]: peak memory: 170
170M    1:47.08
[”20:29:34”]: peak memory: 170
170M    1:47.21
[”20:29:37”]: peak memory: 170
170M    1:47.34
[”20:29:40”]: peak memory: 170
170M    1:47.50
[”20:29:43”]: peak memory: 170
170M    1:47.68
[”20:29:46”]: peak memory: 170
170M    1:47.84
[”20:29:49”]: peak memory: 170
170M    1:48.00
[”20:29:52”]: peak memory: 170
170M    1:48.14
[”20:29:55”]: peak memory: 170
170M    1:48.28
[”20:29:58”]: peak memory: 170
170M    1:48.44
[”20:30:01”]: peak memory: 170
170M    1:48.59
[”20:30:04”]: peak memory: 170
170M    1:48.75
[”20:30:07”]: peak memory: 170
170M    1:48.89
[”20:30:10”]: peak memory: 170
170M    1:49.02
[”20:30:13”]: peak memory: 170
170M    1:49.18
[”20:30:16”]: peak memory: 170
170M    1:49.33
[”20:30:19”]: peak memory: 170
170M    1:49.49
[”20:30:22”]: peak memory: 170
170M    1:49.66
[”20:30:25”]: peak memory: 170
170M    1:49.80
[”20:30:28”]: peak memory: 170
170M    1:49.96
[”20:30:31”]: peak memory: 170
170M    1:50.11
[”20:30:34”]: peak memory: 170
170M    1:50.28
[”20:30:37”]: peak memory: 170
170M    1:50.44
[”20:30:40”]: peak memory: 170
171M    1:50.60
[”20:30:43”]: peak memory: 171
171M    1:50.76
[”20:30:46”]: peak memory: 171
171M    1:50.90
[”20:30:49”]: peak memory: 171
171M    1:51.06
[”20:30:52”]: peak memory: 171
171M    1:51.22
[”20:30:55”]: peak memory: 171
171M    1:51.38
(...)
[”20:48:29”]: peak memory: 185
152M    2:45.78
[”20:48:32”]: peak memory: 185
152M    2:45.95
[”20:48:35”]: peak memory: 185
152M    2:46.10
[”20:48:38”]: peak memory: 185
152M    2:46.25
[”20:48:41”]: peak memory: 185
152M    2:46.43
[”20:48:44”]: peak memory: 185
152M    2:46.57
[”20:48:47”]: peak memory: 185
152M    2:46.74
[”20:48:50”]: peak memory: 185
152M    2:46.91
[”20:48:53”]: peak memory: 185
152M    2:47.09
[”20:48:56”]: peak memory: 185
152M    2:47.26
[”20:48:59”]: peak memory: 185
152M    2:47.40
[”20:49:02”]: peak memory: 185
152M    2:47.54
[”20:49:05”]: peak memory: 185
152M    2:47.69
[”20:49:08”]: peak memory: 185
152M    2:47.83
[”20:49:11”]: peak memory: 185
152M    2:47.97
[”20:49:14”]: peak memory: 185
152M    2:48.14
[”20:49:17”]: peak memory: 185
152M    2:48.29
[”20:49:20”]: peak memory: 185
152M    2:48.44
[”20:49:23”]: peak memory: 185
152M    2:48.58
[”20:49:26”]: peak memory: 185
152M    2:48.72
[”20:49:29”]: peak memory: 185
152M    2:48.87
[”20:49:32”]: peak memory: 185
152M    2:49.02
[”20:49:35”]: peak memory: 185
152M    2:49.17
[”20:49:38”]: peak memory: 185
153M    2:49.31
[”20:49:41”]: peak memory: 185
153M    2:49.48
[”20:49:44”]: peak memory: 185
153M    2:49.63
[”20:49:47”]: peak memory: 185
153M    2:49.79
[”20:49:50”]: peak memory: 185
153M    2:49.95
[”20:49:53”]: peak memory: 185
153M    2:50.12
[”20:49:56”]: peak memory: 185
153M    2:50.30
[”20:49:59”]: peak memory: 185
153M    2:50.49
[”20:50:02”]: peak memory: 185
153M    2:50.64
[”20:50:05”]: peak memory: 185
153M    2:50.78
[”20:50:08”]: peak memory: 185
153M    2:50.94
[”20:50:11”]: peak memory: 185
153M    2:51.12
[”20:50:14”]: peak memory: 185
153M    2:51.29
[”20:50:17”]: peak memory: 185
153M    2:51.46
[”20:50:20”]: peak memory: 185
153M    2:51.62
[”20:50:23”]: peak memory: 185
153M    2:51.76
[”20:50:26”]: peak memory: 185
153M    2:51.91
[”20:50:29”]: peak memory: 185
153M    2:52.06
[”20:50:32”]: peak memory: 185
153M    2:52.21
[”20:50:35”]: peak memory: 185
153M    2:52.36
[”20:50:38”]: peak memory: 185
153M    2:52.50
[”20:50:41”]: peak memory: 185
153M    2:52.65
[”20:50:44”]: peak memory: 185
153M    2:52.79
[”20:50:47”]: peak memory: 185
154M    2:52.94
[”20:50:50”]: peak memory: 185
154M    2:53.10
[”20:50:53”]: peak memory: 185
154M    2:53.24
[”20:50:56”]: peak memory: 185
154M    2:53.42
[”20:50:59”]: peak memory: 185
154M    2:53.57
[”20:51:02”]: peak memory: 185
154M    2:53.73
[”20:51:05”]: peak memory: 185
154M    2:53.89
[”20:51:08”]: peak memory: 185
154M    2:54.02
[”20:51:11”]: peak memory: 185
154M    2:54.17
[”20:51:14”]: peak memory: 185
154M    2:54.32
[”20:51:17”]: peak memory: 185
154M    2:54.47
[”20:51:20”]: peak memory: 185
154M    2:54.60
[”20:51:23”]: peak memory: 185
154M    2:54.76
[”20:51:26”]: peak memory: 185
154M    2:54.89
[”20:51:29”]: peak memory: 185
154M    2:55.02
[”20:51:32”]: peak memory: 185
154M    2:55.18
[”20:51:35”]: peak memory: 185
154M    2:55.33
[”20:51:38”]: peak memory: 185
154M    2:55.49
[”20:51:41”]: peak memory: 185
154M    2:55.61
[”20:51:44”]: peak memory: 185
154M    2:55.75
[”20:51:47”]: peak memory: 185
154M    2:55.90
[”20:51:50”]: peak memory: 185
154M    2:56.04
[”20:51:53”]: peak memory: 185
154M    2:56.19
[”20:51:56”]: peak memory: 185
154M    2:56.35
[”20:51:59”]: peak memory: 185
155M    2:56.55
[”20:52:02”]: peak memory: 185
155M    2:56.72
[”20:52:05”]: peak memory: 185
155M    2:56.85
[”20:52:08”]: peak memory: 185
155M    2:56.99
[”20:52:11”]: peak memory: 185
155M    2:57.15
[”20:52:14”]: peak memory: 185
155M    2:57.31
[”20:52:17”]: peak memory: 185
155M    2:57.48
[”20:52:20”]: peak memory: 185
155M    2:57.63
[”20:52:23”]: peak memory: 185
155M    2:57.79
[”20:52:26”]: peak memory: 185
155M    2:57.91
[”20:52:29”]: peak memory: 185
155M    2:58.10
[”20:52:32”]: peak memory: 185
155M    2:58.25
[”20:52:35”]: peak memory: 185
155M    2:58.38
[”20:52:38”]: peak memory: 185
155M    2:58.50
[”20:52:41”]: peak memory: 185
155M    2:58.65
[”20:52:44”]: peak memory: 185
155M    2:58.78
[”20:52:47”]: peak memory: 185
DrRefactor commented 9 months ago

This commit seems to have fixed the issue: https://github.com/software-mansion/react-native-reanimated/commit/b7f5805c0108a04dc940dd0fb9ef88b951ac1b86

DrRefactor commented 9 months ago

I have bad news @ranaavneet - I've extended my repo repro to use basic animation via useAnimatedStyle, and it leaks again, quite quickly.

https://github.com/DrRefactor/reanimated-issue-5614-repro/blob/main/App.tsx

ranaavneet commented 9 months ago

Hmmm, could you try with #5333

DrRefactor commented 9 months ago

@ranaavneet it's all the same 😞 even more - I removed useAnimatedStyle from my (new) repro, and it still leaks, maybe just a bit slower.

ranaavneet commented 9 months ago

@piaskowyk @tjzel @tomekzaw @Latropos Could shed some light on this. They are the experts!

DrRefactor commented 9 months ago

@piaskowyk @tjzel @tomekzaw @Latropos @ranaavneet

I've isolated the leak to just updating sharedValue.value from JS thread on my repro-repo: https://github.com/DrRefactor/reanimated-issue-5614-repro/blob/main/App.tsx

DrRefactor commented 9 months ago

Both of these cases are enough to cause memory leak, both leak quite fast:

// `s` is a state updated each 50ms
useEffect(() => {
    x.value = s;
  }, [s, x]);

second:

const d = useDerivedValue(() => s);

The second one comes from the first issue, I guess, useDerivedValue uses sharedValue.value setter under the hood.

tomekzaw commented 9 months ago

@DrRefactor can you check if calling gc() function a few times both in JS and UI runtime works? This function triggers the JS garbage collector so it can free some memory

DrRefactor commented 9 months ago

@tomekzaw I did not succeed calling gc on UI thread as this is an object not a function for some reason.

I did call it on JS thread in a 30s interval, and it seems memory does not leak (or not so fast). In 5 minutes RAM usage raised only 3MB vs 25~30MB without calling gc.

DrRefactor commented 9 months ago

I did some experiments, it seems calling runOnUI under the hood of Mutable value setter triggers the leak. This part alone called as a result of sharedValue.value = makes RAM usage grow rapidly:

makeShareableCloneRecursive(() => {
  'worklet';
  queue.forEach(([worklet, args]) => {
    worklet(...args);
  });
  callMicrotasks();
})
DrRefactor commented 9 months ago

I just tested:

Neither of above helped, reanimated2 looked promising in the first 2 minutes, but eventually RAM has gone up from 150MB to 1.2GB...

zhekix commented 9 months ago

any news ?

DrRefactor commented 9 months ago

This particular memory leak is fixed with:

However, we still observe other native memory leaks, that are much tougher to isolate. It'll take some time before I find them and provide minimal reproduction.

ranaavneet commented 9 months ago

Hi @DrRefactor do you know which particular commit(s) between 3.6.2 and 3.7.0 fixed this issue ?

ranaavneet commented 9 months ago

Hey @tomekzaw! Could you post a code example here on how to call gc() on both UI and JS runtimes ? Thanks in advance!

tomekzaw commented 9 months ago

@ranaavneet Here's how you can access gc function in RN and UI runtime in 3 different ways:

  console.log(1, gc);
  console.log(2, global.gc);
  console.log(3, globalThis.gc);

  runOnUI(() => {
    console.log(1, String(gc)); // this is `gc` function from RN runtime, don't call it
    console.log(2, String(global.gc));
    console.log(3, String(globalThis.gc));
  })();

Here's how you can call gc() function in RN and UI runtime:

gc();
// or: global.gc();
// or: globalThis.gc();

runOnUI(() => {
  global.gc();
  // or: globalThis.gc();
})();
ranaavneet commented 9 months ago

Thanks @tomekzaw !

alexstanbury commented 9 months ago

Just wondering if the maintainers of this repo have tests for memory leaks? It seems that they have been a constant problem since version 2, and for those like me who rely on long-running app times it makes reanimated hard to adopt knowing that it's likely the app will eventually crash.

Please don't take this as a dig, I am hugely thankful for the effort the team puts into this library.

DrRefactor commented 8 months ago

@tomekzaw In my case, global.gc is an object, not a function in UI thread. However, calling it from JS thread alone solves (works around?) the issue.

DrRefactor commented 8 months ago

@ranaavneet I'm not sure. There were some major changes in SharedValue implementation, which could have fixed it. Also, this commit alone: https://github.com/software-mansion/react-native-reanimated/commit/b7f5805c0108a04dc940dd0fb9ef88b951ac1b86 fixed the issue of memory leak when only useSharedValue is used (but never updated though).

DrRefactor commented 8 months ago

@tomekzaw @ranaavneet @zhekix

We've finally found the last leak in our production project, it's not reanimated related!

It turns out, React Native's Android native image caching caused memory to slowly grow and crash low-end Android TV 12 devices. Turning off RAM cache solved the problem.