8. Memory Example: FilterStreams

We’ve touched on streaming approaches before, for example, when looking at the effects of memory mapping or when comparing DOM-based XML parsers to those based on SAX or MAX.

In the preceding chapter, we showed how to drastically lower memory consumption by changing the description method that returns an NSString to a streaming describeOn: method that updates an NSMutableString passed into it as an argument.

However, having the argument be an NSMutableString seems to somewhat contradict our advice of having semantically rich objects, and also doesn’t solve the initial problem of an infinite recursion causing a crash. So it shouldn’t come as a surprise that we can do better. In fact, we will briefly introduce an ...

Get iOS and macOS™ Performance Tuning: Cocoa®, Cocoa Touch®, Objective-C®, and Swift™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.