Skip to content

Instantly share code, notes, and snippets.

@wader
Created June 12, 2012 10:05
Show Gist options
  • Save wader/2916698 to your computer and use it in GitHub Desktop.
Save wader/2916698 to your computer and use it in GitHub Desktop.
Help find self references in blocks that might be retain cycles
#!/bin/bash
function check_file() {
echo $1
awk '
/.*/ {
if (inblock > 0) {
collect = collect $0 "\n";
}
line = line + 1
}
/\^{/ {
if(inblock == 0) {
inblock = 1
collect = substr($0, index($0, "^{"))
method = substr($0, 0, index($0, "^{"))
blockline = line
}
}
/}/ {
if (inblock > 0) {
inblock = inblock - 1;
if(inblock == 0) {
p = match(collect, "self\\.");
ignore = match(method, "beginBackgroundTaskWithExpirationHandler|animateWithDuration|dispatch_async|dispatch_after|animations:|addOperationWithBlock:");
if(ignore == 0 && p != 0) {
print "==================================="
print "Found self in block at line " blockline
print method
print collect
}
collect = ""
}
}
}
' \
$1
shift
}
if [ "$1" = "" ] ; then
find . '(' -name *.m -or -name *.mm ')' | \
(while read F ; do check_file "$F" ; done)
else
while [ "$1" != "" ] ; do
check_file "$1"
shift
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment