Skip to content

Fix memory leak in ShimmerView - #357

Merged
ianrumac merged 1 commit into
superwall:ir/feat/minor-fixesfrom
MattSkala:fix/memory-leak
Feb 16, 2026
Merged

Fix memory leak in ShimmerView#357
ianrumac merged 1 commit into
superwall:ir/feat/minor-fixesfrom
MattSkala:fix/memory-leak

Conversation

@MattSkala

@MattSkala MattSkala commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Changes in this pull request

  • Resolves Memory leak when ActivityProvider is provided to Superwall.configure #245
  • The lazy lambdas in ShimmerView.kt captured the constructor context parameter (an Activity), preventing it from being garbage collected even after destruction. Changed context.applicationContextgetContext() in both lazy property initializers at lines 29-34, so the lambdas no longer capture the Activity reference.

Checklist

  • All unit tests pass.
  • All UI tests pass.
  • Demo project builds and runs.
  • I added/updated tests or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • I have run ktlint in the main directory and fixed any issues.
  • I have updated the SDK documentation as well as the online docs.
  • I have reviewed the contributing guide

Greptile Overview

Greptile Summary

Changed lazy property initializers in ShimmerView from context.applicationContext to getContext() to prevent memory leaks. The lazy lambdas previously captured the constructor parameter context, which could be an Activity reference, preventing proper garbage collection. Using getContext() instead ensures the lambdas don't capture the constructor parameter directly.

  • Prevents Activity memory leaks caused by lambda captures in lazy properties
  • Both portraitDrawable and landscapeDrawable properties updated

Confidence Score: 5/5

  • Safe to merge - targeted fix for a specific memory leak issue with minimal risk
  • The change is a simple, well-understood fix that addresses a memory leak caused by lambda capture. The modification replaces direct constructor parameter access with a View method call, preventing the lazy lambda from capturing the Activity context. Since the View is constructed with context.applicationContext at line 18, getContext() returns the same application context, making this a safe refactor with identical behavior but without the memory leak.
  • No files require special attention

Important Files Changed

Filename Overview
superwall/src/main/java/com/superwall/sdk/paywall/view/ShimmerView.kt Fixed memory leak by replacing captured constructor parameter with getContext() calls in lazy properties

Sequence 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!
Loading

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@ianrumac

Copy link
Copy Markdown
Collaborator

Hey @MattSkala !

Thanks for the PR - I'll change the base to another branch which touches ShimmerView and merge it in!

@ianrumac
ianrumac changed the base branch from develop to ir/feat/minor-fixes February 16, 2026 14:10
@ianrumac
ianrumac merged commit 0a35f51 into superwall:ir/feat/minor-fixes Feb 16, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

Memory leak when ActivityProvider is provided to Superwall.configure

2 participants