|
Lim Hock-Chai wrote on 07/12/2006 02:33:10 PM:
If the based pointer already pointed to an allocate memory, shouldn't you dealloc it first before calling subprocedure that return a pointer? Otherwise you might cause memory leak (I think).
You're right that there would be a danger of memory leak in that case. My rule of thumb is that the module that allocates memory should be responsible for deallocating it, so I'd never pass my only pointer to a manually allocated field to a procedure that might clear that pointer. However, it's not hard to copy a pointer to a temp field, and then pass it. I'm not sure if that's completely valid or not, but that's how I learned it, and it generally works out well for me. Mind you, most of the manual allocation/deallocation I've done has been in other languages, but I think the basic concepts and practices should be the same.
The compiler checking I'm referring to is more like in the source code you do something like this: myField_BasePointer = *null; (from everybody's posting, seems like you should always do dealloc(n) myField_BasePoniter)
See Scott's point about multiple pointers to the same memory.
I'm really not too worry about the based pointer pointing to an invalid address (May be I should). I'm more concerned about the memory leak (Memory is cheap, may be I just worry too much. Then again, Chirs just should us a few lines of code that could allocated 300+ GB of memory :)).
Don't get me wrong ... memory leaks can be very, very bad, and are at least equally hard to track down as non-nulled pointers. I'm just saying that I'm happy to take care of it myself, because I don't think it's practical for the compiler (or OS) to do it for me. ##################################################################################### Attention: The above message and/or attachment(s) is private and confidential and is intended only for the people for which it is addressed. If you are not named in the address fields, ignore the contents and delete all the material. Thank you. Have a nice day. For more information on email virus scanning, security and content management, please contact administrator@xxxxxxxxxxxx #####################################################################################
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.