memory keeps growing after subscribing to a channel using Android SDK

Hi all,

When I subscribe to a channel using below API, memory keeps growing, but if I don’t subscribe, there’s no memory issue. ( FYI, for test purpose, I did not handle received message )
I had the same problem with iOS SDK and Slava solved the problem.
I’ve attached screenshot of memory usage.

subscribe(String channelName, int pollingInterval, AsyncCallback<List<Message>>
subscriptionResponder, AsyncCallback<Subscription> responder);

Regards,
Scott

Could you run it over a longer period of time and report your findings?

Also, do you publish any messages? if so, at what rate (messages/second or minute)?

Regards,
Mark

Hi Mark,

Could you run it over a longer period of time and report your findings?

  • The android system halts app process after 10 min, when memory reaches around 30 MB. (from my android device, that is how I found out this memory issue)
    Also, do you publish any messages? if so, at what rate (messages/second or minute)?
  • No, none, it’s got nothing to do with sending or receiving, I am running the app in idle. (doing nothing with it to find out where that memory problem is from)
    You can easily test yourself by running message subscription sample code. As I wrote, it happened with iOS SDK.

Regards,
Scott

Thanks, we will be looking into it.

Hi Scott,

Could you please grab a build of SDK from the URL below and try with it? I made a few changes which should help with memory allocation:

Regards,
Mark

Did not change, memory keeps growing…

To be absolutely sure, could you delete the app from the phone, rebuild and deploy again?

I deleted, re-build, and tried, but no difference.

You really need to wait for more than 10 min to see the difference.

No, if there’s no problem, memory stays under 13 MB, it went up to 18 MB.

And if you do not use subscribe, it doesn’t happen?

Yes, that’s right, memory is always under 13MB.

One other thing, a leak is when memory grows OVER time, but not at the start, which could be due to initial buffering and object allocation

You gotta show me that it grows over time

I don’t know, if that’s the case, memory keeps growing linearly, and it looks like a leak.

Can you try yourself?

I did. See the image below. The program is functioning as expected, there’s no memory leak with the latest code.

http://support.backendless.com/public/attachments/4ca02fc8bbb9bab2a0bf279fa6c756b2.jpg&lt;/img&gt;

And here’s my code I used to test it:

package com.backendless.memoryleaktest;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;


import com.backendless.Backendless;
import com.backendless.Subscription;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.messaging.Message;


import java.util.List;




public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
            Backendless.initApp(this, MY_APP_ID, SECRET_KEY, "v1");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Backendless.Messaging.subscribe( new AsyncCallback&lt;List&lt;Message&gt;>() {
            @Override
            public void handleResponse(List&lt;Message&gt; messages) {
                Log.i( "MEMORY LEAK", "Got messages - " + messages.size() );
            }


            @Override
            public void handleFault(BackendlessFault backendlessFault) {
                Log.i( "MEMORY LEAK", backendlessFault.getDetail() );
            }
        }, new AsyncCallback&lt;Subscription&gt;() {
            @Override
            public void handleResponse(Subscription subscription) {
                Log.i( "MEMORY LEAK", "Subscribed" );
            }


            @Override
            public void handleFault(BackendlessFault backendlessFault) {
                Log.i( "MEMORY LEAK", backendlessFault.getDetail() );
            }
        });
    }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();


        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }


        return super.onOptionsItemSelected(item);
    }


}

Hi Mark,

I’ve tried your code, but it fails to subscribe with fault message code: ‘5008’, message: ‘User has no permission to subscribe’.
If it fails to subscribe, there’s no memory leak.( I think method poll message is where leak is…)
Like below, change your code to subscribe AFTER LOG IN, make sure subscribe is succeeds.

    String loginId = "LoginId";
    String password = "Password";
    try {
        BackendlessUser user = Backendless.UserService.login(loginId, password, false);
        Backendless.Messaging.subscribe( new AsyncCallback&lt;List&lt;Message&gt;>() {
            @Override
            public void handleResponse(List&lt;Message&gt; messages) {
                Log.i( "MEMORY LEAK", "Got messages - " + messages.size() );
            }
            @Override
            public void handleFault(BackendlessFault backendlessFault) {
                Log.i( "MEMORY LEAK", backendlessFault.getDetail() );
            }
        }, new AsyncCallback&lt;Subscription&gt;() {
            @Override
            public void handleResponse(Subscription subscription) {
                Log.i( "MEMORY LEAK", "Subscribed" );
            }
            @Override
            public void handleFault(BackendlessFault backendlessFault) {
                Log.i( "MEMORY LEAK", backendlessFault.getDetail() );
            }
        });
    } catch(BackendlessException ex) {


    }

Regards,
Scott

Hi Scott,

I had absolutely no errors in my app. You are getting an error for the reason that the security permissions in your backend are different than in mine. You are welcome to try it with my app id and secret key and see for yourself:

application id: 757E349F-C515-5AF3-FF5D-EFF0379BFB00
secret key: 115455F0-5317-46D0-FFB2-82712757C900

If a user is logged in or not makes absolutely no difference on the performance or memory allocation of the subscribe operation.

Regards,
Mark