You may be feeling a little uneasy about the following line being called every time the convert: method is called:
converter = [[Converter alloc]init]; |
This line allocates space in memory for a Converter instance and should be deallocated after you use it. You may notice that you didn’t deallocate this instance.
The reason you can do this is because Objective-C 2.0 utilizes garbage collection. To enable garbage collection:
Choose Project > Edit Project Settings
Navigate to the Build tab
Set the value for Objective-C Garbage Collection to Supported under GCC 4.0 - Code Generation.
By supporting garbage collection, you don’t have to worry about deallocating objects you instantiate. You can leave your code just the way it is and not have to worry about memory leaks.
More information about garbage collection can be found in GNU C/C++/Objective-C 4.0.1 Compiler User Guide.
Last updated: 2007-10-31