MonoTouch的:应用程序杀低纪念品,为什么呢?现场字节分配5 MB顶部 [英] MonoTouch: App killed for low mem, Why? Live bytes allocation 5 MB top

查看:125
本文介绍了MonoTouch的:应用程序杀低纪念品,为什么呢?现场字节分配5 MB顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPad应用程序在MonoTouch的发展,因为我想避免所有的内存管理的地狱,但它似乎并不如此。在模拟器上一切正常,但是当我测试我的应用程序在设备上我惊恐地发现,它是由OS一些内存警告后迅速死亡。
我的应用程序是一个简单的图像浏览,它加载某些PNG图像,并显示他们使用的UIScrollView里面的一些UIViews,得到一个触摸时加载一个或上一个。在模拟器上正常工作。但在设备上加载和卸载约6-11影像后,它开始得到内存警告,然后突然进程被杀死。我检查了我所有的实例化周期,我正确地删除加载新的图像前的所有引用。

My iPad app is developed in MonoTouch, because I wanted to avoid all the memory management hell, but it doesn't seem the case. On the simulator everything works fine, but when I tested my app on the device I discovered with horror that it is quickly killed by the OS after some memory warnings. My app is a simple image browser, it loads some PNG images and shows them using some UIViews inside an UIScrollView, loading the next or the previous when getting a touch. On the simulator it works fine. But on the device after loading and unloading about 6-11 images it start getting memory warnings and then suddenly the process is killed. I've checked all my instancing cycles, and I correctly delete all references before loading new images.

于是我就开始仪器和分析开始在我的应用程序的内存分配iPad兼容。在那里,我发现现场字节只有大约5-9 MB,正是我预期,但由于一些奇怪的原因,死者的内存分配几乎没有收集到全部,因为分配约50 MB(小于5-9 MB后它是活字节)是被杀害!这里是仪器分析我的应用程序会话的截图:

So I started Instruments and began profiling the memory allocation of my App on the iPad. There I discovered that the Live bytes are only around 5-9 MB, just what I expected, but for some strange reason the dead memory allocations are almost not collected at all, because after allocating about 50 MB (less than 5-9 MB of it being Live Bytes) it is being killed! Here is a screenshot of the Instruments profiling session of my App:

和这里是heapshots序列:

And here is the heapshots sequence:

< IMG SRC =htt​​p://i.stack.imgur.com/24ibd.pngALT =>

也有一些小的泄漏,但我认为他们没有大到足以成为罪魁祸首。他们都是48字节泄漏的strdup从在的iOS 5.1发布时的UIScrollView一个已知问题:

There are also some small leaks, but I think that they are not big enough to be the culprits. They are all 48 bytes leaks from strdup, a known issue when releasing UIScrollView in iOS 5.1:

我的应用程序被杀害高达50MB iPad上之前呈指数级增长,以及高达314 MB的iPhone4S的,所报告的内存监视器:

Even with everything that seems ok and the Live Bytes allocated are still at 5 MB, the REAL memory of my app grows exponentially before being killed up to 50MB on iPad, and up to 314 MB on the iPhone4S, as reported by the Memory Monitor:

是否有人可以告诉我,如果有一种方法或工具来发现什么,问题出在哪里?它是MonoTouch的垃圾收集器的错误?还是有一些对象,我不正确处置?怎么我能找到那些与分析器? 。我检查我的代码了两天,但一切似乎是正确的。

Does somebody can tell me if there is a method, or an utility to discover what and where the problem is? Is it a bug of the monotouch garbage collector? Or are there some object I don't dispose correctly of? And how I can find those with the profiler? I've checked my code for two days, but everything seems right.

下面是我对装载/实例化/处理周期代码:

Here is my code for the loading/instancing/disposing cycle:

    void StartImageLoadingThread()
{
    tokenSource = new CancellationTokenSource ();
    token = tokenSource.Token;
    Task task1 = new Task( () => PerformLoadImageTask(token),token);
    task1.Start();
}


void PerformLoadImageTask(CancellationToken token)
{
        if (token.IsCancellationRequested)
                {
                     Console.WriteLine("Task {0}: Cancelling", Task.CurrentId);
                return;
                }

            current_uiimage_A = UIImage.FromFileUncached(file_name);
            page_A_image_view.Image = current_uiimage_A;


} 


void UnloadImageAFromMemory()
{
      page_A_image_view.Image = null;
      current_uiimage_A.Dispose();
      current_uiimage_A = null;
}   



有没有赶上那是没有正确处理对象的方法?仪器报道说,现场字节低,泄漏几乎为零,那么为什么死的对象不处理?即使没有在我的应用程序几分钟发生时,GC似乎并没有让他的工作,即使我明确地把它在我的代码。我甚至尝试了新的实验垃圾收集器,但它更是雪上加霜,更快地让我的应用程序被杀害。

Is there a method to catch an object that is not been disposed correctly? Instruments reports that the live bytes are low, leaks are almost zero, then why the dead objects are not disposed of? Even if nothing happens in my app for minutes, the GC doesn't seem to make his job, even if I call it explicity in my code. I even tried the new experimental Garbage Collector, but it is even worse and quicker to make my app killed.

我找不到任何指导或一步一步的指导在Xamarin网站解决内存警告或跟踪坏分配。

I cannot find any guideline or step-by-step guide on the Xamarin website for troubleshooting memory warnings or tracking down bad allocations.

任何帮助或建议非常赞赏,
谢谢!

Any help or suggestion is very appreciated, Thanks!

更新:
我已经减少的大小和一些图像和uiviews,以及Live字节的分辨率,现在是从9 MB降至5 MB顶部,但应用程序仍被杀后, 。一些内存警告不管是什么

UPDATE: I've reduced the size and the resolution of some images and uiviews, and the Live Bytes are now dropped from 9 MB to 5 MB top, but the app is still killed after some memory warnings no matter what.

更新2:
的建议哈维尔我已经删除了后台任务,并直接进行调用和内存泄漏走了!看来,MonoTouch的垃圾收集器有一个bug,无法收集内存时UIImages分配和布置在不同的线程。但现在我的应用程序是,当我非常滚动反应迟钝,所以我需要找到一个解决办法做到这一点在不同的线程!但如何?

UPDATE 2: As suggested by Javier I've removed the background tasks and made the calls directly and the memory leak is gone! It seems that the MonoTouch garbage collector have a bug and is unable to collect memory when UIImages are allocated and disposed in a different thread. But now my app is awfully unresponsive when I scroll, so I need to find a solution to do it in a different thread! But how?

推荐答案

我与 UIImage.FromFile 的问题。我的应用程序加载了很多PNG图像的使用任务,并显示在主线程它。

I had problems with UIImage.FromFile. My app is loading a lot of png images using a task, and showing it in the main thread.

我添加了一个 GC.Collect的在后台任务,但它并没有解决了这一问题。我不得不删除后台任务,做所有的东西,在主线程和呼叫 GC.Collect的。似乎Image.Dispose不释放图像存储器:(

I added a GC.Collect in the background task, but it hasn't fixed the problem. I had to remove the background task, do all the stuff in the main thread AND call GC.Collect. It seems that Image.Dispose is not releasing the image memory :(

但是如果你有其他任务这是行不通的,所以我不得不将其删除:(

But it doesn't work when you have another task, so i had to remove it :(

是的,它是不工作....

Yes it is not working....

这篇关于MonoTouch的:应用程序杀低纪念品,为什么呢?现场字节分配5 MB顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆