Updated: use __unsafe_unretained and fix key from CTParagraphStyleRef #166

Merged
merged 2 commits into from Apr 10, 2012

Projects

None yet

2 participants

@tonycn
Contributor
tonycn commented Apr 10, 2012

The las commit should be ok, through there is a trick for the key, but cleaner than the previous change.

Finally two changes:

  1. Use __unsafe_unretained to be compatible with ios4 and ios5;
  2. Fix key of CTParagraphStyleRef by remove memory address info from "<" char to the end of string

I was running DemoApp for allocation profiling by instrument.
Made a heap, and token snapshots for repeat step "Enter ReadMe Sample -> Back to Home -> Enter ReadMe Sample -> Back to Home ..."
I found there were 10+ DTCoreTextParagraphStyle objects increased each time.
And instrument tell that most come from "NSString *key = [(__bridge id)ctParagraphStyle description];"

Solved the issue in a inelegant way by format all the values needed.

@odrobnik
Collaborator

How is that a memory leak? Details, please.

@tonycn
Contributor
tonycn commented Apr 10, 2012

@Cocoanetics I was running DemoApp for allocation profiling by instrument. Made a heap, and token snapshots for repeat step "Enter ReadMe Sample -> Back to Home -> Enter ReadMe Sample -> Back to Home ..." I found there were 10+ DTCoreTextParagraphStyle objects increased each time. And instrument tell that most come from "NSString *key = [(__bridge id)ctParagraphStyle description];"

@tonycn
Contributor
tonycn commented Apr 10, 2012

Cannot figure out the reason yet.

@tonycn
Contributor
tonycn commented Apr 10, 2012

Finally found the reason, the description for key is like following. "<CFArray 0x7ed43d0 [0x20eab48]>" diffs each time, so the DTCoreTextParagraphStyle cache is never used.

Description of CTParagraphStyleRef
CTParagraphStyle:
writing direction = -1, alignment = 4, line break mode = 0, default tab interval = 36
first line head indent = 0, head indent = 27, tail indent = 0
line height multiple = 0, maximum line height = 0, minimum line height = 0
line spacing adjustment = 0, paragraph spacing = 0, paragraph spacing before = 0
tabs:
<CFArray 0x7ed43d0 [0x20eab48]>{type = immutable, count = 2, values = (
0 : CTTextTab: location = 22, alignment = 1, options = (none)

1 : CTTextTab: location = 27, alignment = 0, options = (none)

)}

@tonycn tonycn Rollback 2 commits; Change block weak ref variable compile flag to __…
…unsafe_unretained to be compatible with ios4 and ios5; fix key of CTParagraphStyleRef by remove address info
07a4dd5
@odrobnik

I suspect that this might cause problems when comparing a paragraph style that is identical to another one except for the tab stops. Can you instead have a function that creates a nice well-formed key for a given CTParagraphStyleRef?

@tonycn
Contributor
tonycn commented Apr 10, 2012

@Cocoanetics just removed the address from description string of CTParagraphStyleRef

@odrobnik odrobnik merged commit 0c38cf0 into Cocoanetics:master Apr 10, 2012
@odrobnik
Collaborator

Thanks for the work on the fixes!

@tonycn
Contributor
tonycn commented Apr 10, 2012

It's a pleasure. I am going to use this lib in the app. Thanks for the cool framework for html render on iOS!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment