Memory Management :-
Depending on the type of application you’re writing, judicious use of memory can be
critical. For example, if you’re writing an interactive drawing application that creates
many objects during the execution of the program, you must take care that your program
doesn’t continue to consume more memory resources as it runs. In such cases, it becomes
your responsibility to intelligently manage those resources and free them when they’re no
longer needed.This means freeing resources during the program’s execution instead of
just waiting until the end.NSAutorelease :- When dealing with a foundation programs you must setup this pool to use the foundation object.
When the pool is setup foundation automatically adds certain array,string etc when you are done using the pool you can release the memory is use by send its drain message [pool darain].
predefined classes.NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
In UserDefine Classes(autorelease):-
[objectname autorelease];
Release :- When you no longer needed an objects you dicrement its refrence count by ONE ,send its release message like [objectname release].
Reference Countinng:-
You can’t free up the memory an object uses until you are certain that everyone is done using that object.Luckily ,the foundation framework provides the elegant solution for keeping track of the number of refrences to an object .It involves a fairly straightforward thechnique calles a refrence counting.
When an object is create via a alloc method or new keyworkd a copy of message its refrence count is set to ONE each time you needed to ensure that the object be kept arround you increment its refrence count by ONE sending its retain message.
[objtname retain]
Delloc :- When the refrence count object reach a ZERO, system knows that this object is no longer needed so it is free by its memory this done by message delloc.
[objectname delloc]
Garbage Collection :-
you have been creating your programs to run in a memorymanaged
runtime environment.The memory-management rules summarized in the previous sections apply to such an in environment,which you deal with autorelease pools, issues related to retaining and releasing objects, and object ownership.
As of Objective C 2.0, an alternate form of memory management, known as garbage
collection, became available.With garbage collection, you don't have to worry about retaining
and releasing objects, autorelease pools, or retain counts. The system automatically
keeps tracks of what objects own what other objects, automatically freeing up (or garbagecollecting)
keeps tracks of what objects own what other objects, automatically freeing up (or garbagecollecting)
objects that are no longer referenced as space is needed during the program’s
execution.
No comments:
Post a Comment