google / google/j2objc

Retain cycles in jdk based classes

Open
#2,678 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6k
Forks
999
Avg merge
19h 20m
Merged PRs (30d)
14

Description

I found retain cycles in JDK based java classes which cause memory leaks on iOS. Below are some snapshots from Instrument Leaks tool.

- [LinkedHashMap](https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html) retain cycle:

![Image](https://github.com/user-attachments/assets/207c1631-c957-4476-ae3c-da7da6f999e6)

- [DateTimeFormatterBuilder](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html) retain cycle:

![Image](https://github.com/user-attachments/assets/154f740f-058e-438d-ad6a-adc9e53ea9c8)

Similarly, there seems retain cycle in [AbstractMap](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html). Because `AbstractMap` retains `values` and `values()` use anonymous inner class which has implicit reference back to `AbstractMap`.

Does j2objc takes care of memory leaks in JDK by patching them or any other way ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.