0

I just ran into this problem. I have a XWalkView (Crosswalk WebView) inside my Android Application. Inside the XWalkView i make a couple of AJAX requests, the problem is that the Java Garbage Collector is freeing up the memory whilst i'm doing the request. Therefor the request is unable to finish.

As for the AJAX part, i'm using qwest, a simple library for doing AJAX requests using promises.

The Java code for this is pretty simple, i don't think this is the problem:

webView = (XWalkView)findViewById(R.id.walk_view);
webView.setResourceClient(new MyAppWebViewClient(webView));
webView.setWillNotCacheDrawing(true);
webView.load("file:///android_asset/www/index.html", null);

I added the willNotCacheDrawing to try and free up more memory, so that the request can finish, this is not helping much.

MyAppWebViewClient is a subclass of XWalkResourceClient, it's not doing that much, just triggering a different Action when a PDF is loaded. The problem also occurs when i don't use my own ResourceClient.

The HTML / JavaScript part is super simple, it downloads no more than 0.5MB, with a request like this:

qwest.get('my.server.com/api')
 .then(function(xhr, response) {
    // do work with response
    // to bad it never reaches this
 })
 .catch(function(xhr, response, e) {
    // I just get a timeout here,
    // there is no way the server is timing out,
    // it works perfectly on iOS, Web and any other platform
 });

I figured this has something to do with the Garbage Collector because if i look at the Memory Monitor, this is what happens while doing the request:

Garbage collector at work?

The first 'rise' in memory is when the request starts, as soon as the memory usage becomes stable again, the request has failed. I figured the sudden drops is the Garbage Collector freeing up memory that i just allocated for my AJAX request.. hmm.

I am quite new to Android Development, especially when it comes to memory management. Is it normal that the garbage collector doesn't let me allocate more than 7,76MB of RAM? It seems a little low for a full app.

Do you guys have any idea?

Thanks!

Erik Terwan
  • 2,710
  • 19
  • 28
  • You have shown that GC is performed during the time frame of your request, which is unremarkable, and you have not substantiated your rather outlandish assertion that reachable objects are (erroneously) collected during the process. I don't buy it. What exception is thrown, and / or what error code is produced as a result of the failure? Or do you just get unexpected results? – John Bollinger Nov 24 '15 at 15:10
  • I just get unexpected results, qwest it keeps on trying, but fails after some time. Saying that the maximum execution time has passed. I figure this has something to do with CrossWalk? – Erik Terwan Nov 24 '15 at 15:13
  • If you just get unexpected results then the most likely reason is that there is a flaw in *your* code. From its name, I suppose `MyAppWebViewClient` is your own class; I'd look there. For us to do more than speculate, however, you'll need to provide an [MCVE](http://stackoverflow.com/help/mcve). – John Bollinger Nov 24 '15 at 15:17

1 Answers1

1

This not really abnormal, slightly small but not surprising. If you need more information about available heap memory for a single process you may read How much memory for Android process or the official documentation on memory management under Android. You will see that heap size is in general very limited.

Community
  • 1
  • 1
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
  • Thanks! So the heap size is normal. I fixed the issue by doing the large AJAX request via Java, then passing that data back to the webview, that way i have more control over how the memory is managed. This is ok because the large AJAX request is only being done once a session. – Erik Terwan Nov 24 '15 at 15:26