简体   繁体   English

Android Garbage Collector在AJAX请求中间释放内存

[英]Android Garbage Collector freeing memory in the middle of an AJAX request

I just ran into this problem. 我只是遇到了这个问题。 I have a XWalkView ( Crosswalk WebView) inside my Android Application. 我的Android应用程序中有一个XWalkView( Crosswalk WebView)。 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. 我在XWalkView内发出几个AJAX请求,问题是Java垃圾收集器在执行请求时正在释放内存。 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. 至于AJAX部分,我使用的是qwest ,这是一个使用Promise进行AJAX请求的简单库。

The Java code for this is pretty simple, i don't think this is the problem: Java代码非常简单,我不认为这是问题所在:

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. 我添加了willNotCacheDrawing来尝试释放更多的内存,以便请求可以完成,这没有太大帮助。

MyAppWebViewClient is a subclass of XWalkResourceClient , it's not doing that much, just triggering a different Action when a PDF is loaded. MyAppWebViewClient是的子类XWalkResourceClient ,它没有做那么多,只是触发不同的动作时加载PDF。 The problem also occurs when i don't use my own ResourceClient. 当我不使用自己的ResourceClient时,也会发生此问题。

The HTML / JavaScript part is super simple, it downloads no more than 0.5MB, with a request like this: HTML / JavaScript部分非常简单,下载量不超过0.5MB,请求如下:

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: 我认为这与垃圾收集器有关,因为如果我查看内存监视器,这是在执行请求时发生的情况:

垃圾收集器在工作吗?

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. 我认为突然下降是垃圾收集器释放了我刚刚为我的AJAX请求分配的内存。

I am quite new to Android Development, especially when it comes to memory management. 我对Android开发非常陌生,尤其是在内存管理方面。 Is it normal that the garbage collector doesn't let me allocate more than 7,76MB of RAM? 垃圾收集器不允许我分配超过7,76MB的RAM是否正常? It seems a little low for a full app. 完整的应用似乎有点低。

Do you guys have any idea? 你们有什么主意吗?

Thanks! 谢谢!

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 . 如果您需要有关单个进程可用堆内存的更多信息,请阅读Android进程的内存量Android下内存管理官方文档。 You will see that heap size is in general very limited. 您将看到堆大小通常非常有限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM