Javier Ferrero
Javier Ferrero

Reputation: 8811

Titanium Mobile Android: Memory not released when app is closed

We have developed an app using Titanium Mobile. When we first run the app in an Android device it uses around 25MB of memory. But every time we exit the app by using the device back button and then relaunch the app, the memory usage goes up by 10MB. So if we exit and relaunch the app 5 times, the app ends up using 50MB of extra memory, for a total usage of 75MB. If we launch the app a few more times, the app will simply not start, and the following error is thrown:

Uncaught Error: Failed to load resource, Java exception was thrwon. Source = assets.readAsset(assetPath);

We initially thought it was a problem of our app, so we develop a simple app to test the issue. This test app just creates a window and adds a label to it. The app.js is the following:

function createView() {

    var win1 = Titanium.UI.createWindow({  
        title:'Tab 1',
        backgroundColor:'#fff',
        exitOnClose: true
    });

    var label1 = Titanium.UI.createLabel({
        color:'#999',
        text:'I am Window 1',
        font:{fontSize:20,fontFamily:'Helvetica Neue'},
        textAlign:'center',
        width:'auto'
    });

    win1.add(label1);

    win1.open();    
}

createView();

Well, the test app has the same problem as our original app. The first time it is launched it consumes 14MB of memory. After 5 restarts (using the device back button) it is consuming 21MB (150% of the inital memory).

We have also tried the sample app that is generated when you create a project in Titanium and the Kitchen Sink app developed by Titanium. The results are the same.

Our tests are done using Titanium 3.0.0.GA with two different devices:

We have searched for a solution to this problem with no results. We do not want to believe this is the normal behaviour of Titanium, because if so, Titanium is simply not an option for us. Has anyone found any solution/workaround for this issue?

Thanks in advance

UPDATE: added tiapp.xml of test app

<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
    <id>com.cloudship.titanium.mobile.test</id>
    <name>titanium-mobile-test</name>
    <version>1.0</version>
    <publisher>Javier</publisher>
    <url>http://</url>
    <description>not specified</description>
    <copyright>2013 by Javier</copyright>
    <icon>appicon.png</icon>
    <persistent-wifi>false</persistent-wifi>
    <prerendered-icon>false</prerendered-icon>
    <statusbar-style>default</statusbar-style>
    <statusbar-hidden>false</statusbar-hidden>
    <fullscreen>false</fullscreen>
    <navbar-hidden>true</navbar-hidden>
    <analytics>true</analytics>
    <guid>18e506f3-02d4-4fb7-84b7-ff8d4c1fac82</guid>
    <property name="ti.ui.defaultunit" type="string">system</property>
    <iphone>
        <orientations device="iphone">
            <orientation>Ti.UI.PORTRAIT</orientation>
        </orientations>
        <orientations device="ipad">
            <orientation>Ti.UI.PORTRAIT</orientation>
            <orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
            <orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
            <orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
        </orientations>
    </iphone>
        <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application android:debuggable="true"/>
            <supports-screens android:anyDensity="true"/>
        </manifest>
    </android>
    <mobileweb>
        <precache/>
        <splash>
            <enabled>true</enabled>
            <inline-css-images>true</inline-css-images>
        </splash>
        <theme>default</theme>
    </mobileweb>
    <modules/>
    <deployment-targets>
        <target device="iphone">false</target>
        <target device="ipad">false</target>
        <target device="blackberry">false</target>
        <target device="android">true</target>
        <target device="mobileweb">false</target>
    </deployment-targets>
    <sdk-version>3.0.0.GA</sdk-version>
</ti:app>

Upvotes: 2

Views: 1143

Answers (3)

Javier Ferrero
Javier Ferrero

Reputation: 8811

It is a bug in Titanium 3.0.0.GA. See jira ticket here. Fortunately it has been fixed in 3.0.2.

Answer was given in Titanium Q&A

Upvotes: 1

sundar nataraj
sundar nataraj

Reputation: 8692

this is solution to memory woes..please go through this thread

https://developer.appcelerator.com/question/116867/this-is-a-solution-to-your-memory-woes

Upvotes: 0

mr.VVoo
mr.VVoo

Reputation: 2270

i'm also developing Titanium. I checked my app and I'm not experiencing this problems on Android 2.2.2 on an HTC Desire. The app is closed correctly.

Can you test with the following code:

var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff',
    exitOnClose: true
});

var label1 = Titanium.UI.createLabel({
    color:'#999',
    text:'I am Window 1',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});

win1.add(label1);

win1.open(); 

so remove the surrounding function.

Upvotes: 0

Related Questions