Open Bug 1510669 Opened 6 years ago Updated 6 months ago

Performance Warning: Static Field Leaks

Categories

(GeckoView :: General, enhancement, P5)

Unspecified
Android
enhancement

Tracking

(Not tracked)

People

(Reporter: fluffyemily, Unassigned, Mentored)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug, Whiteboard: [lang=java])

Attachments

(2 files)

A static field will leak contexts.  

Non-static inner classes have an implicit reference to their outer class. If that outer class is for example a Fragment or Activity, then this reference means that the long-running handler/loader/task will hold a reference to the activity which prevents it from getting garbage collected.  

Similarly, direct field references to activities and fragments from these longer running instances can cause leaks.  ViewModel classes should never point to Views or non-application Contexts.

Affected Classes:

GeckoAppShell
GeckoBatteryManager
GeckoMediaDrmBridgeV21
GeckoNetworkManager
GeckoSystemStateListener
Some/most/all? (definitively the GeckoBatteryManager and GeckoNetworkManager) of those are singletons that are intended to live as long as the app itself and only hold onto an *application* context.
Keywords: good-first-bug
OS: Unspecified → Android
Priority: -- → P5
Product: Firefox for Android → GeckoView
Severity: normal → S3

Enhancements should have severity N/A.

Severity: S3 → N/A
  • mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsPlayer.java:49: Do not place Android context classes in static fields (static reference to DefaultBandwidthMeter which has field context pointing to Context); this is a memory leak
  • mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV21.java:517: This AsyncTask class should be static or leaks might occur (org.mozilla.gecko.media.GeckoMediaDrmBridgeV21.PostRequestTask)
  • mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoNetworkManager.java:47: Do not place Android context classes in static fields (static reference to GeckoNetworkManager which has field mContext pointing to Context); this is a memory leak

Adding @SuppressLint("StaticFieldLeak") and use static class for AsyncTask.

Mentor: m_kato
Whiteboard: [lang=java]

Hello!
I am new to contribute to open source projects.
I just wanted to ask whether this task could be assigned to me so that I can try to solve it and start my contributing journey.

(In reply to Yash from comment #4)

Hello!
I am new to contribute to open source projects.
I just wanted to ask whether this task could be assigned to me so that I can try to solve it and start my contributing journey.

Assigned.

Assignee: nobody → shindeyash0567

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit BugBot documentation.

Assignee: shindeyash0567 → nobody

If this bug is still open and unassigned, may i try to fix it?

(In reply to Hardik Koul from comment #7)

If this bug is still open and unassigned, may i try to fix it?

Yes, see comment #3.

(In reply to Makoto Kato [:m_kato] from comment #8)

(In reply to Hardik Koul from comment #7)

If this bug is still open and unassigned, may i try to fix it?

Yes, see comment #3.

Sure , thanks. Starting off with setting the repo up in my local.

Hey Makoto,
I am done with mercurial and git hannibal setup, but while fetching remote , im getting this error

Fetching central
fatal: repository 'https://hg.mozilla.org/mozilla-central/' not found
error: Could not fetch central
Fetching inbound
fatal: repository 'https://hg.mozilla.org/integration/mozilla-inbound/' not found
error: Could not fetch inbound

are the URLs correct for the repos?

Flags: needinfo?(m_kato)
Flags: needinfo?(m_kato)
Assignee: nobody → creatinggalaxy
Status: NEW → ASSIGNED

Here is the patch with the changes suggested : (https://phabricator.services.mozilla.com/D185046)

however im aware suppressing the Lint warning is not an optimal way to solve this memory leak issue, let me know if i can try to figure out any optimal solution for that.

also apologies for submitting a duplicate patch with just a white space change, please delete that if possible.

Any update on this ??

(In reply to Hardik Koul from comment #17)

Any update on this ??

https://phabricator.services.mozilla.com/D185046's status is "Changes Planned". So this isn't reviewable status. If this is ready for code review, please change status to "Needs Review".

(In reply to Makoto Kato [:m_kato] from comment #18)

(In reply to Hardik Koul from comment #17)

Any update on this ??

https://phabricator.services.mozilla.com/D185046's status is "Changes Planned". So this isn't reviewable status. If this is ready for code review, please change status to "Needs Review".

Hey, sorry was not aware of that process, have updated the status now to "Needs Review" https://phabricator.services.mozilla.com/D185046

Attachment #9346693 - Attachment description: WIP: Bug 1510669 - Adding @SuppressLint("StaticFieldLeak") and using static class for "PostRequestTask" → Bug 1510669 - Adding @SuppressLint("StaticFieldLeak") and using static class for "PostRequestTask"

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit BugBot documentation.

Assignee: creatinggalaxy → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: