Skip to content
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

Memory leak in Route class #477

Open
HilaryN opened this issue Jul 11, 2021 · 4 comments
Open

Memory leak in Route class #477

HilaryN opened this issue Jul 11, 2021 · 4 comments

Comments

@HilaryN
Copy link
Contributor

HilaryN commented Jul 11, 2021

Android Studio is giving a warning in the Route.kt class:
"Do not place Android context classes in static fields (static reference to 'Route' which has field context_ pointing to Context); this is a memory leak."

@oliverlockwood
Copy link
Member

I think this issue is quite widespread, and may be quite involved to refactor away from. Given we've not (to my knowledge) observed any issues as a result of this, I recognise the issue but wouldn't say we should necessarily give it a high priority.

@HilaryN
Copy link
Contributor Author

HilaryN commented Jul 16, 2021

Agreed, yes.

@HilaryN
Copy link
Contributor Author

HilaryN commented Oct 3, 2021

LiveRide freezes on my Fairphone 2 (though fine on my FP3) and I've tracked it down to this. I'm working on a fix - it seems to be possible to pass the context as a parameter in the functions which need it.
It only freezes when moving (cycling / walking / other transport!). It also freezes when in Journey Planner and moving. I'm not quite sure what that has to do with the Route class, but if I take out context_ it doesn't seem to freeze.

@HilaryN
Copy link
Contributor Author

HilaryN commented Nov 24, 2021

Now I'm not so sure that's the problem.
It doesn't freeze on commit 5652817 / 1st May 2020 / "Audit CycleStreets.net/cyclestreets.org links", but freezes on commits after that.
If I take 5652817 and convert the Route class to Kotlin without doing any other change except minimal ones for it to work, then it freezes.
If I then change context to be passed as a parameter rather than stored in the static var it still freezes :-(
If I then remove LocationOverlay it doesn't freeze. (A bit hard to navigate without the LocationOverlay, but just about possible! :-) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants