views:

154

answers:

2

Possible Duplicate:
Which is preferable: Free or FreeAndNil?

when to use free and freeandnil?

in my way, i usually use the .free when the object that created is something like "object.create;" that has no self or nil parameter. if there is, that's the time i will use the freeandnil();

am i doing it right? or it has a big deference?

A: 

according to blog.eurekalog.com it is better to use the FreeAndNil always rather than Free. For the reason that it is a clean freeing the allocated memory use in your program to avoid leaks., .free also can avoid leaks.

check here for more info Free vs. FreeAndNil

XBasic3000
Free avoids leaks too, and neither Free nor FreeAndNil 'clean' the memory which was used by the object instance.
mjustin
+2  A: 

FreeAndNil sometimes works against you; see the article "a case against FreeAndNil" from Allen Bauer (Chief Scientist at Embarcadero) about the use of FreeAndNil and the follow up article by him titled "a case when FreeAndNil is your enemy".

Note that FreeAndNil is not bad, but you need to know what it does to oversee its consequences.

--jeroen

Jeroen Pluimers