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

Fix memory leak due to builder with Context in constructor #3023

Merged
merged 1 commit into from
May 22, 2020

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented May 22, 2020

Description

Removing the builder from the constructor. It's not a good idea to add the Context to the builder because it creates memory leaks. Taking @Guardiola31337 suggestion to throw it in the build(..) function. That function converts the context to an applicationContext to save memory leaks.

This issue was introduced here #3015

There is an outstanding issue for refactoring the MapboxDistanceFormatter #3016

  • I have added any issue links
  • I have added all related labels (bug, feature, new API(s), SEMVER, etc.)
  • I have added the appropriate milestone and project boards

Testing

Please describe the manual tests that you ran to verify your changes

  • I have tested locally (including SNAPSHOT upstream dependencies if needed) through testapp/demo app and run all activities to avoid regressions
  • I have tested via a test drive, or a simulation/mock location app
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have updated the CHANGELOG including this PR

@kmadsen kmadsen force-pushed the km-fix-directions-format-leak branch from 3fd8e1f to 5a2743f Compare May 22, 2020 19:16
@kmadsen kmadsen changed the title Remove builder from distance formatter constructor Fix memory leak due to builder with Context in constructor May 22, 2020
@kmadsen kmadsen added this to the v1.0.0 milestone May 22, 2020
@kmadsen kmadsen added the bug Defect to be fixed. label May 22, 2020
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2020

Codecov Report

Merging #3023 into master will decrease coverage by 0.01%.
The diff coverage is 42.10%.

@@             Coverage Diff              @@
##             master    #3023      +/-   ##
============================================
- Coverage     36.76%   36.75%   -0.02%     
  Complexity     2216     2216              
============================================
  Files           554      554              
  Lines         19955    19955              
  Branches       1886     1886              
============================================
- Hits           7337     7334       -3     
- Misses        11782    11784       +2     
- Partials        836      837       +1     

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix @kmadsen

@kmadsen kmadsen force-pushed the km-fix-directions-format-leak branch from 0e05c82 to 1f396cf Compare May 22, 2020 19:54
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of minor comments.

* @param locale the locale to use for localization of distance resources
* @param unitType to use, or UNDEFINED to use default for locale country
* @param roundingIncrement increment by which to round small distances
* @param builder used for updating options
*/
class MapboxDistanceFormatter private constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #2709 (comment)

For example, MapboxDistanceFormatter will be renamed to DistanceFormatOptions which can be passed to components requiring distance formatting.

Do we still want to do that? Maybe in a separate ticket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah finding MapboxDistanceFormatter to be a larger project. So the progress can be tracked here #3016

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MapboxDistanceFormatter is a service, so renaming to DistanceFormatOptions actually doesn't make sense. updating the source ticket

@kmadsen kmadsen force-pushed the km-fix-directions-format-leak branch from 816b150 to 4d9041f Compare May 22, 2020 20:57
@kmadsen kmadsen force-pushed the km-fix-directions-format-leak branch from 4d9041f to 619e9db Compare May 22, 2020 21:02
@kmadsen kmadsen added the backwards incompatible Requires a SEMVER major version change. label May 22, 2020
@kmadsen kmadsen merged commit 1ebc86f into master May 22, 2020
@kmadsen kmadsen deleted the km-fix-directions-format-leak branch May 22, 2020 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards incompatible Requires a SEMVER major version change. bug Defect to be fixed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants