Hyperloop on Android - memory leak of Activities

时间:2018-06-04 17:40:51

标签: android titanium appcelerator-hyperloop hyperloop

I have a classic Appcelerator Titanium app (without Alloy) for Android and I am using Hyperloop to utilize a third-party library for image processing. An issue that I came across is that my app leaks Activity objects whenever I use the current Android activity from the Titanium API and cast it to a Hyperloop object. I need this as the third-party library requires an Activity object for an object constructor. However, it seems to me that there is a more fundamental issue with either the Hyperloop Android implementation or my incorrect usage of it.

I put together the most simplistic app which seems to reproduce the issue.

app.js contents:

var Activity = require('android.app.Activity');

var mainWin = Ti.UI.createWindow({
    title: 'Main window'
});

var button = Ti.UI.createButton({
    title: 'Open new window'
});

button.addEventListener("click", function(e) {
   var win = createSecondWindow();
   win.open();
});

mainWin.add(button);

mainWin.open();

createSecondWindow = function() {
   var secondWin = Ti.UI.createWindow({
        title: 'Second window'
    });

   secondWin.addEventListener("open", function (e) {
        var activity = new Activity(Ti.Android.currentActivity);
        activity = null;
    });

    return secondWin;
};

Now if I open and close multiple times the second window and then do a memory dump (using the Android profiler in Android studio) after forcing a garbage collection, I see multiple instances of org.appcelerator.titanium.TiActivity which are retained in memory by hyperloop.InstanceProxy objects. My understanding is that these should have been removed after the garbage collection.

enter image description here

I am using the latest versions of TI SDK (7.1.1.GA) and hyperloop 3.0.5. The test device is running Nexus 5 with Android 6.0.1.

My question is whether I am doing something wrong with the Hyperloop and the Activity or this is probably an issue with Hyperloop itself.

0 个答案:

没有答案