frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
451 stars 138 forks source link

Low memory bug #282

Closed master255 closed 1 year ago

master255 commented 1 year ago

Tracked down a rare bug. The app closes lowMemoryKiller if many torrents are added. This code fixes the problem completely.

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        Runtime.getRuntime().gc();
    }

@gubatron @proninyaroslav You need to add this to the main activity.

gubatron commented 1 year ago

Hope you're doing well, thank you for reporting this.

Are you talking about a crash when an Android app finds itself onLowMemory() and main activity being whatever the main activity in an Android app? (wonder if you meant to report this on the FrostWire for Android repo, or if this is a jlibtorrent issue with your android app)

master255 commented 1 year ago

For some reason, Android does not do the memory cleanup itself when there is not enough memory in the system. This command forcibly starts the cleanup. With this command, the torrent app closes much less frequently.

gubatron commented 1 year ago

so it then seems like a garbage collection issue with android and less a jlibtorrent issue.

I suppose then, if you have multiple Activities (like we do on FrostWire for Android), it makes sense to force garbage collection if this onLowMemory callback is called.

Thank you!