But can anyone please provide real demos showing FreeAndNil is really needed? And if we change that FreeAndNil then the program will cause error.
FreeAndNil or not have been discussed for years but still have no a mutual agreement.
But if till then still no one is able to provide a real demo then I will keep believing 99% Free only is enough.
I normally stay away from discussions about OOP but, in this particular case, it's not just about OOP.
The "clean" (for lack of a better word) way is to use FreeAndNil. The reason is very simple, a class is a pointer to a heap memory block. Once the memory block has been freed, it should not be accessed again. If the class/pointer has not been nil-ed then it is possible to dereference the pointer after the memory has been freed, which is a programming error but, it often won't be visible immediately. if the pointer is nil-ed then any subsequent de-reference will cause an access violation (as it should) revealing the programming error right then and there.
As far as compile-able code, the subject "FreeAndNil" in the FPC Wiki, has an example that shows the problem with just Free. It's also worth noting that there is code out there that tests if some class is Assigned before it proceeds to do something with it. If the class/pointer is freed and not nil-ed, Assigned will return TRUE causing the rest of the code to access memory that is completely unrelated to the tested class.
Basically, whether in OOP or any other kind of programming, if a variable points to a dynamically allocated memory block and, the memory block is freed then the variable should be set to nil because whatever value it had got invalidated when the block got freed.
Think of it as variable "re-initialization". The variable should be nil before a memory block is allocated to hold the class, it should be reset to nil when the block is freed. That way the value/state of the variable mirrors the state of what it represents (as it should.)