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

Android Kotlin Realm SDK - possible memory leak #1402

Closed
siserivan opened this issue May 30, 2023 · 3 comments
Closed

Android Kotlin Realm SDK - possible memory leak #1402

siserivan opened this issue May 30, 2023 · 3 comments
Labels
Encryption:Off Frequency:Always More-information-needed More information needed from the reporter. The issue will autoclose if no more information is given. O-Community Repro:Always SDK-Use:Local T-Bug Waiting-For-Reporter Waiting for more information from the reporter before we can proceed

Comments

@siserivan
Copy link

siserivan commented May 30, 2023

How frequently does the bug occur?

Always

Description

First of all, I'm not sure if this is a bug or I'm using the SDK on the wrong way.

For more than a year I was using Java SDK for my Android projects (mostly in combination with Dagger-Hilt, coroutines & flows, jetpack compose) and didn't have any problem with a hight usage of memory inside my apps.

On my newest Android project I decided to migrate to Kotlin SDK. This project is mostly based on server-driven UI (displaying full content on screens with UI provided from backend API). In a specific case - every time user changes the language in app, I need to call multiple endpoints (more than 10) to refresh that content with a new and cache everything for offline mode, I noticed that my app become significantly slower.

Then I run some performance test with Profiler inside Android Studio and noticed that every time I'm saving something in realm database in multiple transactions, memory significantly increase and stays in RAM. First I checked that I'm doing everything fine Dagger-Hilt and that my ViewModels are getting disposed when they should. Then I thought it is something with coroutine flows and observer, but everything was fine also with them.

I created a smaller project to check what is it going on and removed everything expect methods to save data in realm database. Here are results:

Java SDK - app running with maximum around 170MB usage in Debug mode (on graph it is possible to see that memory is getting disposed)
image

Kotlin SDK -- app running with maximum around 360MB usage in Debug mode (on graph we can see that memory is only raising)
image

Here is a heap memory dump graph on my larger project that is using Kotlin SDK.

Again, I'm still not sure if there is any problem with Kotlin Realm SDK or I'm doing something wrong. Any help and information will be good, thanks!

If you need I can create public git repository with both cases, feel free to contact me about anything.

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

  1. First I created some model with about 15 attributes
  2. In a loop with small delay, I tried to save 1000 random data of the same object in database, every saving was in it's own thread (coroutine).
  3. I done this test with both Java and Kotlin SDK (newest versions)

Version

1.8.0 gradle plugin

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 13

Build environment

Android Studio: Flamingo 2022.2.1 Patch 1
Android Gradle Plugin Version: 7.3.1
Gradle version: 7.4
Kotlin version: 1.7.20
Realm Kotlin Gradle Plugin: 1.8.0
Compile SDK: 33
Realm coroutines: 1.6.4

@cmelchior
Copy link
Contributor

Hi @siserivan Thank you for reporting this. This looks similar to #1393 which we are already looking into.

But if you have the opportunity to provide a small sample Kotlin project that would be very helpful so we are 100% certain we are measuring the same thing.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Jun 5, 2023
@nhachicha
Copy link
Collaborator

Hi @siserivan we did recently a couple of memory leak fixes, could you please try this again with the latest version?

@sync-by-unito sync-by-unito bot added the More-information-needed More information needed from the reporter. The issue will autoclose if no more information is given. label Nov 13, 2023
Copy link
Contributor

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Encryption:Off Frequency:Always More-information-needed More information needed from the reporter. The issue will autoclose if no more information is given. O-Community Repro:Always SDK-Use:Local T-Bug Waiting-For-Reporter Waiting for more information from the reporter before we can proceed
Projects
None yet
Development

No branches or pull requests

3 participants