Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created February 18, 2019 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romyilano/b608ae257ffc2971996c268deb21b1e9 to your computer and use it in GitHub Desktop.
Save romyilano/b608ae257ffc2971996c268deb21b1e9 to your computer and use it in GitHub Desktop.
This is SO useful!
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html
– (id)findMatchingObject:(id)anObject {
id match;
while (match == nil) {
@autoreleasepool {
/* Do a search that creates a lot of temporary objects. */
match = [self expensiveSearchForObject:anObject];
if (match != nil) {
[match retain]; /* Keep match around. */
}
}
}
return [match autorelease]; /* Let match go and return it. */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment