|
Lim Hock-Chai wrote:
Does anybody know what will happen to the memory of myField1 after the dealloc myField1_p statement? Does it become available for used?
The memory is still there, but it is illegal to use it. But there is no exception given for illegal use.
dealloc myField1_p; // I'm still able to use it. // Will the memory get use by other alloc operation because of above // dealloc? myField2 = %trim(myField2) + 'BBB';
The memory could be allocated for some other use at any time. From looking at your code, it seems impossible that it could be allocated again after your dealloc, but the storage might be reallocated for some other use in the middle of your %trim or concatenation. Don't play around with deallocated storage. It's impossible to predict what bizarre or bad things might happen if you use storage that is not allocated to you. Scott's parking lot analogy is a good one. Imagine leaving your parking space, driving around the block, and driving back into the parking space blindfold. Now imagine what might be happening to the parking space at the moment you decide to reuse it illegally: - it might never have been used again, and you could drive right in - it might have been used by someone else, who has already left, and you could drive right in - it might be occupied by another car, and you would dent both your car and theirs - someone might have dug a deep hole in it, and your car would fall into the hole - someone might be crossing the parking space on foot, and you would crush them with your car Just as you wouldn't try this "reuse the parking space" exercise even for fun, you shouldn't try the "reuse the deallocated pointer" exercise for fun either.
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.