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

@SystemService for WifiManager causes a memory leak #1628

Closed
ened opened this Issue Nov 17, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@ened
Contributor

ened commented Nov 17, 2015

Given I have an Activity with a @SystemService reference to WifiManager:

@SystemService
WifiManager wifiManager;

Then AA will generate this code:

wifiManager = ((WifiManager) this.getSystemService(Context.WIFI_SERVICE));

Which in turn might cause a memory leak (Eclipse MAT):
screen shot 2015-11-17 at 18 50 25

Once I researched and found this page:
https://code.google.com/p/android/issues/detail?id=43945

And then proceeded to change the code in onCreate like this:

wifiManager = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE));

The leak disappeared. Should've known this a few hours ago.

Therefore, I suggest that AA generates the @SystemService code for WifiManager as above. (perhaps good to add a comment into the generated code as well).

@WonderCsabo

This comment has been minimized.

Show comment
Hide comment
@WonderCsabo

WonderCsabo Nov 17, 2015

Member

Good catch! Wanna contribute?

Member

WonderCsabo commented Nov 17, 2015

Good catch! Wanna contribute?

@WonderCsabo WonderCsabo added the Defect label Nov 17, 2015

@ened

This comment has been minimized.

Show comment
Hide comment
@ened

ened Nov 17, 2015

Contributor

OK.

Contributor

ened commented Nov 17, 2015

OK.

@ened

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment