The Cocoa Memory Management Regular Expression
Any method whose selector matches this regular expression gives you a reference to its return value, which you must later release.
/^retain$|^(alloc|new)|[cC]opy/
As an added extra bonus, here’s the CF equivalent.
/Create|Copy|Retain/
Carbon adds several exceptions, such as GetControlData (which returns a reference to CF things like the string value of a text field). Use Cocoa instead and your memory-management life will be simpler. ;)
February 25th, 2007 at 06:03:29
This is a great idea! I just don’t know how to use it… Everytime I do a project find with the expression above, it only finds lines with ‘Copy/’. What am I doing wrong?
February 25th, 2007 at 12:17:03
Don’t include the slashes.
You only need them in vim, ex, less, and similar programs, to indicate where the regular expression begins and ends. In Mac programs, including Xcode, the regex needs no delimiters, as the field itself does that job.