2012-08-16 42 views
1

我在我的應用程序中使用CoreText,我有一個非常大的泄漏,但我無法找出它爲什麼會發生。所以這裏是我的代碼片段:如何發佈CTFramesetter?

_framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_mAttributedString); 

CFDictionaryRef frameOptionsDictionary = (CFDictionaryRef)[self frameOptionsDictionary]; 

_frame = CTFramesetterCreateFrame(_framesetter, 
           CFRangeMake(0, _mAttributedString.length), 
           path, 
           frameOptionsDictionary); 

CFRelease(_framesetter), _framesetter = NULL; 

正如你所看到的,我放開了我CTFramesetter ......但應用程序泄漏,儀器顯示我CTFramesetter導致這一點。那麼我應該如何釋放它呢?

回答

0

0)確保沒有失敗:

assert(_mAttributedString); 
assert(0 == _framesetter); 
_framesetter = CTFramesetterCreateWithAttributedString(
          (CFAttributedStringRef)_mAttributedString); 

CFDictionaryRef frameOptionsDictionary = 
        (CFDictionaryRef)[self frameOptionsDictionary]; 

assert(path); 
assert(0 == _frame); 
_frame = CTFramesetterCreateFrame(_framesetter, 
           CFRangeMake(0, _mAttributedString.length), 
           path, 
           frameOptionsDictionary); 

CFRelease(_framesetter), _framesetter = NULL; 
+0

好,我檢查,我沒有失敗 – 2012-08-16 06:29:59

+0

@flybirdx被這個報告爲泄漏?我知道我的一個應用程序使用了大量的CT渲染 - 我看到的一個問題是字形加載消耗了大量內存 - 但實際上並沒有標記爲泄漏。 – justin 2012-08-16 06:38:06

+0

不,它沒有被標記,但我使用了堆積分析,它表明這個對象沒有釋放。問題在於,在許多重繪之後,我的應用程序中的所有內容都變得很慢。 – 2012-08-16 07:09:23