内存问题:分配的对象的潜在泄漏

发布于 2024-11-27 22:03:12 字数 1796 浏览 0 评论 0原文

当我分析我的 projetc 时,Xcode 分析器发现分配的对象存在一些潜在的泄漏 但问题是我不知道这意味着什么以及如何解决这个问题

这是我的文件的图片

这是代码

#import "RoundRect.h"

//
// NewPathWithRoundRect
//
// Creates a CGPathRect with a round rect of the given radius.
//
CGPathRef NewPathWithRoundRect(CGRect rect, CGFloat cornerRadius)
{
    //
    // Create the boundary path
    //
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL,
        rect.origin.x,
        rect.origin.y + rect.size.height - cornerRadius);

    // Top left corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x,
        rect.origin.y,
        rect.origin.x + rect.size.width,
        rect.origin.y,
        cornerRadius);

    // Top right corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x + rect.size.width,
        rect.origin.y,
        rect.origin.x + rect.size.width,
        rect.origin.y + rect.size.height,
        cornerRadius);

    // Bottom right corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x + rect.size.width,
        rect.origin.y + rect.size.height,
        rect.origin.x,
        rect.origin.y + rect.size.height,
        cornerRadius);

    // Bottom left corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x,
        rect.origin.y + rect.size.height,
        rect.origin.x,
        rect.origin.y,
        cornerRadius);

    // Close the path at the rounded rect
    CGPathCloseSubpath(path);

    return path;

}

感谢您非常有用的帮助。

PS:我的所有项目在 iPhone 模拟器中都运行良好 这是一个应用程序,有一个选项卡栏和 4 个部分,其中两个部分是空的, 另外两个部分是带有详细视图的表格视图(数据是从 plist 中选取的) 当我在我的设备上测试该应用程序时,两个空部分完美地工作,并且仅两个表视图之一显示详细视图,在模拟器中工作的第二个表视图女巫没有推送详细视图, 让我生气的是,今天早上它运行良好

一个问题: 是一个受其包含的数据限制的 plist,我的意思是,如果有一个大列表,例如包含 500 个字典项目,这会影响应用程序的良好显示吗?

谢谢

when i analyse my projetc, Xcode analyser find some potential leak of an object allocated
but the trouble is that i don't know what it means and how to resolve this

here is a picture of my file,

enter image description here

and here is the code

#import "RoundRect.h"

//
// NewPathWithRoundRect
//
// Creates a CGPathRect with a round rect of the given radius.
//
CGPathRef NewPathWithRoundRect(CGRect rect, CGFloat cornerRadius)
{
    //
    // Create the boundary path
    //
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL,
        rect.origin.x,
        rect.origin.y + rect.size.height - cornerRadius);

    // Top left corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x,
        rect.origin.y,
        rect.origin.x + rect.size.width,
        rect.origin.y,
        cornerRadius);

    // Top right corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x + rect.size.width,
        rect.origin.y,
        rect.origin.x + rect.size.width,
        rect.origin.y + rect.size.height,
        cornerRadius);

    // Bottom right corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x + rect.size.width,
        rect.origin.y + rect.size.height,
        rect.origin.x,
        rect.origin.y + rect.size.height,
        cornerRadius);

    // Bottom left corner
    CGPathAddArcToPoint(path, NULL,
        rect.origin.x,
        rect.origin.y + rect.size.height,
        rect.origin.x,
        rect.origin.y,
        cornerRadius);

    // Close the path at the rounded rect
    CGPathCloseSubpath(path);

    return path;

}

Thanks for your very useful help.

PS: all my projet works fine in the iphone simulator
it's an app, with a tabbar and 4 section, two section are empty yet,
and the two other section are tableview with detail view (data are picked from a plist)
When i test the app on my device, the two empty sections works perfectly, and juste one of the two tableview display the detailview, the second tableview witch works in the simulator did not push the detailview,
what made me mad is that it works fine this morning

A question:
is a plist limited by the data it contain, i mean that if a have a big list for example with 500 dictionary items, can this trouble the good display of the app ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想念有你 2024-12-04 22:03:12

返回 CF/CG 分配时,该函数应以 Create 为前缀。

即重命名您的函数 CreatePathWithRoundRect() 并且分析器应该停止抱怨。

请注意,您不想将自动释放与 CG/CF 类型相勾结;也就是说,遵循包含返回对象类型的框架所延续的模式。因此,从该函数返回 +1 保留计数对象是有意义的。

When returning a CF/CG allocation, the function should be prefixed with Create.

I.e. rename your function CreatePathWithRoundRect() and the analyzer should stop complaining.

Note that you don't want to collude autorelease with CG/CF types; that is, follow the patterns perpetuated by the framework containing the type of the object returned. Thus, returning a +1 retain count object from that function makes sense.

雨落星ぅ辰 2024-12-04 22:03:12

关于潜在的泄漏:

分析器似乎将您的 NewPathWIth.... 方法解释为便利构造函数;这样的构造函数按照约定返回 autorelease 对象。所以我想你应该删除分析器警告:

 return [path autorelease];

这对于你使用返回值的方式是否可以,我不知道......我的意思是:如果你像现在一样返回对象,你不需要被叫方保留;如果您将其返回为自动释放,则被调用者可能需要保留它(如果它需要它的时间比当前执行的方法长)。

至于plist问题,我认为plist没有限制。问题是你用它做什么。如果您要创建一个包含 500 行的表视图,这已经很多了,但由于表视图针对单元格的管理方式进行了优化,因此应该没有问题。无论如何,需要更多信息(这可能是要问的第二个问题)。

About the potential leak:

it seems that the analyzer is interpreting your NewPathWIth.... method as a convenience constructor; such constructor by convention return autoreleases objects. So I guess that yo remove the analyzer warning you should do:

 return [path autorelease];

whether this is ok with how you are using that return value, I don't know... what I mean is: if you return the object like you do now, you do not need that the called retains it; if you return it autoreleased, the called could need to retain it if it needs it for longer than the current executing method.

As to the plist question, I don't think that there is a limit on plist. The question is what you do with it. If you are creating a table view with 500 rows, that is much, but since a table view is optimized as to how cells are managed, it should be no problem. In any case, more information is needed (and possibly this is a second question to ask S.O.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文