내보기로 UILabel의를 추가하는 기능을 가지고 : 메모리 누수가 발생합니까?
@interface UIStyle : NSObject {
NSString * fontName;
CGFloat fontSize;
UIColor* textColor;
UIColor* backgroundColor;
}
그래서 난, 같은 레이블이보기에 추가 내가 메모리 누수를 얻을 : UIStyle이 인터페이스를 가지고
UILabel* AddLabel(UIView* view,CGRect labelRect, UIStyle* labelStyle, NSString* labelText)
{
UILabel* label = [[[UILabel alloc] initWithFrame:labelRect] autorelease];
label.textColor = [UIColor colorWithCGColor:[ labelStyle.textColor CGColor]];
label.backgroundColor = [UIColor colorWithCGColor:[labelStyle.backgroundColor CGColor]];
label.font =[UIFont fontWithName: labelStyle.fontName] size:labelStyle.fontSize];
label.frame = labelRect;
label.text = labelText;
[view addSubview:label];
return label;
}
합니다. 여기 인스트루먼트의 추적입니다 :
0 libSystem.B.dylib calloc
1 CoreGraphics CGGlyphBitmapCreate
2 CoreGraphics CGFontCreateGlyphBitmap8
3 CoreGraphics CGFontCreateGlyphBitmap
4 CoreGraphics create_missing_bitmaps
5 CoreGraphics CGGlyphLockLockGlyphBitmaps
6 0x317c173f
7 0x317c3e59
8 CoreGraphics CGContextDelegateDrawGlyphs
9 CoreGraphics draw_glyphs
10 CoreGraphics CGContextShowGlyphsWithAdvances
11 WebCore WebCore::Font::drawGlyphs(WebCore::GraphicsContext*, WebCore::SimpleFontData const*, WebCore::GlyphBuffer const&, int, int, WebCore::FloatPoint const&, bool) const
12 WebCore WebCore::Font::drawGlyphBuffer(WebCore::GraphicsContext*, WebCore::GlyphBuffer const&, WebCore::TextRun const&, WebCore::FloatPoint&) const
13 WebCore WebCore::Font::drawSimpleText(WebCore::GraphicsContext*, WebCore::TextRun const&, WebCore::FloatPoint const&, int, int) const
14 WebCore WebCore::Font::drawText(WebCore::GraphicsContext*, WebCore::TextRun const&, WebCore::FloatPoint const&, int, int) const
15 WebCore drawAtPoint(unsigned short const*, int, WebCore::FloatPoint const&, WebCore::Font const&, WebCore::GraphicsContext*, WebCore::BidiStatus*, int)
16 WebCore -[NSString(WebStringDrawing) __web_drawInRect:withFont:ellipsis:alignment:letterSpacing:lineSpacing:includeEmoji:truncationRect:measureOnly:]
17 WebCore -[NSString(WebStringDrawing) _web_drawInRect:withFont:ellipsis:alignment:lineSpacing:includeEmoji:truncationRect:measureOnly:]
18 WebCore -[NSString(WebStringDrawing) _web_drawInRect:withFont:ellipsis:alignment:lineSpacing:includeEmoji:truncationRect:]
19 UIKit -[NSString(UIStringDrawing) _drawInRect:withFont:lineBreakMode:alignment:lineSpacing:includeEmoji:truncationRect:]
20 UIKit -[NSString(UIStringDrawing) drawInRect:withFont:lineBreakMode:alignment:lineSpacing:includeEmoji:]
21 UIKit -[NSString(UIStringDrawing) drawInRect:withFont:lineBreakMode:alignment:lineSpacing:]
22 UIKit -[UILabel _drawTextInRect:baselineCalculationOnly:]
23 UIKit -[UILabel drawTextInRect:]
24 UIKit -[UILabel drawRect:]
25 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:]
26 QuartzCore -[CALayer drawInContext:]
27 QuartzCore backing_callback(CGContext*, void*)
28 QuartzCore CABackingStoreUpdate
29 QuartzCore -[CALayer _display]
30 QuartzCore -[CALayer display]
31 QuartzCore CALayerDisplayIfNeeded
32 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
33 QuartzCore CA::Transaction::commit()
34 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
35 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
36 CoreFoundation __CFRunLoopDoObservers
37 CoreFoundation __CFRunLoopRun
38 CoreFoundation CFRunLoopRunSpecific
39 CoreFoundation CFRunLoopRunInMode
40 GraphicsServices GSEventRunModal
41 GraphicsServices GSEventRun
42 UIKit -[UIApplication _run]
43 UIKit UIApplicationMain
44 Cuisine main /iPhone/Projects/iCookProFullSix/iCookPrototype/main.m:14
그리고이 기능 AddLabel 여러 통화에 대한 그들의 수백이있다.
가 왜 이렇게입니다 .. 누수가 없다 -
AddLabel(self.view, CGRectMake(56, 60, 88, 15), style2, @"text");
것은 내가 label.font =[UIFont fontWithName: labelStyle.fontName] size:labelStyle.fontSize];
를 언급하는 경우이다 : 나는 이런 식으로 전화 ? iOS의 버그 또는 내가 잘못하고있는 것입니까?
P. 이 누출은 기기에서만 볼 수 있습니다.
아무도 도와 줄 수 있습니까? 미리 감사드립니다!
또한 시뮬레이터가 아닌 장치에서만 발생하는 유사한 누출도 발생합니다. – nan
코드에서 clang 정적 분석기를 실행하면 문제를 쉽게 찾을 수 있습니다. –
댓글을 주셔서 감사합니다.하지만 clang으로 앱을 확인한 결과 아무 것도 표시되지 않습니다. – azia