RxSwiftCommunity / RxTheme

Theme management based on Rx
MIT License
382 stars 29 forks source link

memory leak? #16

Closed alouanemed closed 4 years ago

alouanemed commented 4 years ago

When profiling the app with instruments' Leaks, it shows that rxtheme leaked somewhere. I couldn't find the place exact, so I went and started generating memory graph using Xcode, and it shows this leak:

runtime: Memory Issues - (1 leaked type): 13 instances of Swift closure context leaked

image instrument output

checking some of those issues revealed that are linked to RxTheme. like this one below: taken from a Button class:

func makeUI() {

        themeService.rx
            .bind({ UIImage(color: $0.primary, size: CGSize(width: 1, height: 1)) }, to: rx.backgroundImage(for: .normal))
            .bind({ UIImage(color: $0.primary.withAlphaComponent(0.9), size: CGSize(width: 1, height: 1)) }, to: rx.backgroundImage(for: .selected))
            .bind({ UIImage(color: $0.primary.withAlphaComponent(0.6), size: CGSize(width: 1, height: 1)) }, to: rx.backgroundImage(for: .disabled))
            .disposed(by: rx.disposeBag)

As I am navigating through the other screens, the number pop's up to 100 Swift closure context leaked. Anyway to solve this? Thanks.

wddwycc commented 4 years ago

hi @alouanemed , can you provide a sample project to reproduce the issue ?

alouanemed commented 4 years ago

OKay, let me create one.

wddwycc commented 4 years ago

@alouanemed any progress ?

alouanemed commented 4 years ago

@wddwycc I tried to reproduce the issue but couldn't. Most leaks are related to RxSwift (including RxTheme). I created this repo https://github.com/alouanemed/leakTest that resembles my project but haven't yet able to reproduce. let me give another try.

wddwycc commented 4 years ago

I would close this one since it's not reproducable.