The memory COULD be unsecure. However, it's the object manager's duty to make sure that it isn't. COM objects keep track of how many pointers/references you have to them, and only free the memory until they are all gone (if you Release properly).
The memory COULD be unsecure. However, it's the object manager's duty to make sure that it isn't. COM objects keep track of how many pointers/references you have to them, and only free the memory until they are all gone (if you Release properly).
Not being familiar with object factories, I can only offer speculation, and it'll be based on the definition of object factory here (even though it's from Java):Hey, would you mind offering your clarification here for me.
http://java.sun.com/products/jndi/tu...jects/factory/
So my guess is, an object factory works something like this:
So what happens is, a SomeObject object is constructed using the data provided, and this object is returned - i.e. a copy of it is made, and then s is constructed by some method that involves the returned copy - and then the return statement ends, and this temporarily constructed SomeObject object goes out of scope and is destroyed, and the copy that s was constructed from also goes out of scope and is destroyed. But s has already been constructed/copied in some sequence from the originally created object, and therefore since it is a copy and not a pointer to the original, it is not destroyed.Code:SomeObject createObject(int arg1, int arg2, double arg3) { return SomeObject(arg1, arg2, arg3, someDataOnlyThisFunctionCanAccess); } ... SomeObject s = createObject(1, 2, 3.4);
Alternately, the object factory might return a pointer to a dynamically created object (i.e. created using new), and therefore the object never goes out of scope and must be deleteed manually.
>>as long as there was a viable pointer to a memory location than the object persisted
You can emulate this using smart pointers that implement reference-counting (take a look here for an example of how it can be done manually), but it is by no means automatically done for you. As far as I know, COM uses reference counting, and if you forget to free a resource then the reference count never reaches 0 and the resource is never destroyed as it should be.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Ahh I see. Thankyou Hunter2 and skorman00; that was very enlightening.
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
Shatki,
Great example. Thanks.
skorman00,
Thanks for your responses, too.