当我使用以下代码在/ Document中加载动态字体时,内存使用将增加字体大小。我不想在不使用该字体时取消注册,因为增加的内存大小太大。
static func readFont(fileName: String) -> Bool
{
let home = NSHomeDirectory() as NSString
let docPath = home.appendingPathComponent("Documents") as NSString
print("docPath: \(docPath)")
let filePath = docPath.appendingPathComponent(fileName)
guard let fontData = NSData(contentsOfFile: filePath) else
{
return false
}
let fontDataProvider = CGDataProvider(data: CFBridgingRetain(fontData) as! CFData)
let cgFont = CGFont(fontDataProvider!)
if cgFont == nil
{
return false
}
var fontError: Unmanaged<CFError>?
CTFontManagerUnregisterGraphicsFont(cgFont!, nil)
if CTFontManagerRegisterGraphicsFont(cgFont!, &fontError)
{
return true
}
else
{
fontError?.release()
}
return false
}
那么,当我不使用此字体时该怎么办?