Fix memory leak in ShimmerView - #357
Merged
ianrumac merged 1 commit intoFeb 16, 2026
Merged
Conversation
Collaborator
|
Hey @MattSkala ! Thanks for the PR - I'll change the base to another branch which touches ShimmerView and merge it in! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes in this pull request
ActivityProvideris provided toSuperwall.configure#245ShimmerView.ktcaptured the constructor context parameter (an Activity), preventing it from being garbage collected even after destruction. Changedcontext.applicationContext→getContext()in both lazy property initializers at lines 29-34, so the lambdas no longer capture the Activity reference.Checklist
CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.ktlintin the main directory and fixed any issues.Greptile Overview
Greptile Summary
Changed lazy property initializers in
ShimmerViewfromcontext.applicationContexttogetContext()to prevent memory leaks. The lazy lambdas previously captured the constructor parametercontext, which could be an Activity reference, preventing proper garbage collection. UsinggetContext()instead ensures the lambdas don't capture the constructor parameter directly.portraitDrawableandlandscapeDrawableproperties updatedConfidence Score: 5/5
context.applicationContextat line 18,getContext()returns the same application context, making this a safe refactor with identical behavior but without the memory leak.Important Files Changed
getContext()calls in lazy propertiesSequence Diagram
sequenceDiagram participant Activity participant ShimmerView participant Lazy Properties participant GC as Garbage Collector Note over Activity,ShimmerView: Before Fix Activity->>ShimmerView: new ShimmerView(activityContext) ShimmerView->>Lazy Properties: lazy { context.applicationContext } Note over Lazy Properties: Lambda captures constructor<br/>parameter 'context' (Activity) Activity->>Activity: Activity destroyed GC->>Activity: Cannot collect (held by lazy) Note over Activity,GC: Memory Leak! Note over Activity,ShimmerView: After Fix Activity->>ShimmerView: new ShimmerView(activityContext) ShimmerView->>Lazy Properties: lazy { getContext() } Note over Lazy Properties: Lambda calls method,<br/>no capture of 'context' Activity->>Activity: Activity destroyed GC->>Activity: Successfully collected Note over Activity,GC: No Memory Leak!(2/5) Greptile learns from your feedback when you react with thumbs up/down!