book
book copied to clipboard
CH 15 Section 06 should be shortened, reordered and made easier to read
trafficstars
Let's drop the parts talking about specially constructed code that creates a reference cycle. Let's start with the practical goal of writing the tree data structure, which is discussed at the end of the chapter. Let's do it without Weak first and show the problems with that approach - first stack overflow, then the reference counts. Then introduce Weak and show the working code.
Rationale:
- The chapter would be more interesting to read, as it would progress from the task, through the initial approach towards the working code.
- It would show how reference cycles happen during actual development, not created on purpose.
- Software developers are generally more interested in ways of debugging code than in ways of writing a bad program.
- One code example would be used instead of two.
The title could be changed to "Preventing Reference Cycles" - that would fit better stylistically that "Reference Cycles Can Leak Memory". Also, memory leaks are not the only issue with reference cycles, as the stack overflow indicates.
I can submit a PR if there is interest in making the change.