TheArchitect123 / KmpEssentials

KmpEssentials is a library that contains apis (40+ Modules) to accelerate your development. Everything from managing the Battery, File System, getting Package information, or taking Photos. Supports iOS, Android & AppleWatch
MIT License
169 stars 2 forks source link

[Android] [Backgrounding & Workers] WorkManager and Context #15

Open Monabr opened 1 month ago

Monabr commented 1 month ago

Hello.

I looked at the implementation of WorkManager and something confused me.

We pass code to WorkManager directly, but usually DI is used for this. Won't your implementation leak memory?

For example, if I have a dependency that uses Application Context, and WorkManager lives longer than Application and can run for 10 minutes after Application is closed - doesn't this indicate that such interaction will lead to memory leak in your implementation?

I first saw that executable code was passed to WorkManager using lambda. I have never seen such implementations.

KmpBackgrounding.createAndStartWorker(null){
    // my action to run in the background
    // this action will run even if the device is locked
}