MonoTouch CoreGraphics与CGPDFDocument和CGPDFPage有关的PDF内存问题 [英] MonoTouch CoreGraphics PDF memory issues with CGPDFDocument and CGPDFPage

查看:114
本文介绍了MonoTouch CoreGraphics与CGPDFDocument和CGPDFPage有关的PDF内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经和MonoTouch合作了3个星期,一切都很顺利,直到我不得不在我的应用程序中显示PDF。

I've been working with MonoTouch for 3 weeks now and everything was going great until I had to display PDFs in my app.

使用Apple的 Quartz 2D编程指南我设法显示PDF。

Using Apple's Quartz 2D Programming Guide I managed to display the PDF.

问题是,应用程序内存不足。我尝试在CGPDFDocument和CGPDFPage对象上使用Dispose()方法,但后来我收到此错误:

The problem is, that the app runs out of memory. I tried to use the Dispose() methods on the CGPDFDocument and CGPDFPage objects, but then I get this error:

Stacktrace:

  at (wrapper managed-to-native) MonoTouch.CoreGraphics.CGPDFPage.CGPDFPageRelease (intptr) <0xffffffff>
  at MonoTouch.CoreGraphics.CGPDFPage.Dispose (bool) <0x00044>
  at MonoTouch.CoreGraphics.CGPDFPage.Finalize () <0x0002b>
  at (wrapper runtime-invoke) object.runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr) <0x0007b>

Native stacktrace:

0   FlapMag1                            0x00037514 mono_handle_native_sigsegv + 412
1   FlapMag1                            0x0000c010 mono_sigsegv_signal_handler + 348
2   libSystem.B.dylib                   0x339927f3 _sigtramp + 34
3   libCGVolute.A.dylib                 0x31c83d88 CPModelRelease + 24
4   libCGVolute.A.dylib                 0x31c84ad4 model_release + 56
5   CoreGraphics                        0x3113ced8 pdf_page_finalize + 68
6   CoreFoundation                      0x3388fae9 _CFRelease + 168
7   CoreFoundation                      0x3388f9c7 CFRelease + 66
8   CoreGraphics                        0x3113ce90 CGPDFPageRelease + 20
9   FlapMag1                            0x00248cc0 wrapper_managed_to_native_MonoTouch_CoreGraphics_CGPDFPage_CGPDFPageRelease_intptr + 64
* Assertion: should not be reached at ../../../../mono/mini/mini-darwin.c:258

T他慢慢地让我发疯,因为我尝试了我能想到的一切。

This slowly drives me mad, because I tried everything I could think of.

在Apple的例子中,有CGPDFDocumentRelease和CGPDFPageRelease,但MonoTouch中缺少这些。因此我认为MT会自动管理这些对象,但显然它没有或者它是错误的。

In Apple's example there is the CGPDFDocumentRelease and CGPDFPageRelease, but these are missing from MonoTouch. Therefore I thought MT manages these object automatically, but apparently it doesn't or it's buggy.

即使我没有弄乱CGPDF对象的Dispose(),当我从superview中删除包含PDF的视图时,会出现上述错误。

Even when I don't mess with the CGPDF object's Dispose(), the above error occurs, when I remove the view, that contains the PDF, from the superview.

有人能够在MonoTouch中使用PDF吗?

Has someone been able to work with PDFs in MonoTouch?

提前致谢。

更新:

我在Obj-测试了PDF绘图C使用相同的PDF并发现当我不调用CGPDFDocumentRelease()时,内存消耗与MonoTouch一样快速上升。通过在Obj-C中调用CGPDFDocumentRelease(),内存消耗是正常的。

因此我认为MonoTouch确实没有释放CGPDFDocument和CGPDFPage对象,当我尝试手动或间接释放它们时(通过删除包含它们的视图,我得到上述错误。

UPDATE:
I tested PDF drawing in Obj-C with the same PDFs and found out that when I don't call CGPDFDocumentRelease() the memory consumption has the same tendency to go rapidly up as in MonoTouch. By calling the CGPDFDocumentRelease() in Obj-C the memory consumption is normal.
Therefore I think that MonoTouch really doesn't free up the CGPDFDocument and CGPDFPage objects and when I try to free them manually or indirectly (by removing the views which contain them), I get the above error.

这很糟糕,现在很有可能,我必须重写Obj-C中的代码... F $#k !!

This sucks big time and it is a real possibility now, that I have to rewrite the code in Obj-C ... F$#k!!

另一个更新:

我仍​​然无法解密为什么我得到与版本相关的错误,但我制作了一个MonoTouch和一个XCode项目,基本上做同样的事情:绘制PDF文件。

我比较了Activity Monitor中两者的内存使用情况,发现虽然MonoTouch应用程序不断增加内存使用量,但XCode却没有。我甚至在MonoTouch中调用CGPDFDocument对象上的Dispose(),但内存消耗仍在增加。

两个应用程序都没有因发布相关错误而崩溃,但是真的很担心mem的使用量会大大增加MonoTouch应用程序...

ANOTHER UPDATE:
I'm still not able to decypher why I get the release related errors, but I made a MonoTouch and an XCode project, where both do essentially the same thing: draw PDFs.
I compared the memory usage of both in Activity Monitor and found out that while the MonoTouch app increases memory usage constantly, the XCode one doesn't. I even call the Dispose() on the CGPDFDocument object in MonoTouch and still the memory consumption increases.
Neither apps crash with the release related error, but it's really worrying that the mem usage is so drasticly larger in the MonoTouch app...

我认为我的问题出在其他地方,但我来到这里是因为我的主要应用程序在内存消耗过高后崩溃了我似乎无法忍受找到一种方法来降低它,因为我得到了这些恼人的发布错误。

I figure that my problem lies somewhere else, but I got here because my main app crashed after mem consumption got too high and I can't seem to find a way to bring it down, because I get these annoying release errors.

和另一个更新:

绘制pdf的代码视图的Draw()方法:

AND ANOTHER UPDATE:
The code that draws the pdf in the view's Draw() method:

CGContext context = UIGraphics.GetCurrentContext();

context.SaveState();

CGPDFDocument pdfDoc = CGPDFDocument.FromUrl(_pdfFileUrl);
if(pdfDoc.Pages >= 1)
{
    CGPDFPage pdfPage = pdfDoc.GetPage(1);  

    context.ScaleCTM(SCALE.Width, SCALE.Height);
    // the PDFRectangle is the media box rect of the page, which is hardcoded
    // for now
    context.TranslateCTM(-this.PDFRectangle.X, -this.PDFRectangle.Height - this.PDFRectangle.Y);

    context.DrawPDFPage(pdfPage);
}

pdfDoc.Dispose();

context.RestoreState();


推荐答案

这是由MonoTouch Alpha中的一个错误引起的将在版本1.9.3中修复

This was caused by a bug in the MonoTouch Alpha which will be fixed in version 1.9.3

这篇关于MonoTouch CoreGraphics与CGPDFDocument和CGPDFPage有关的PDF内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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