Hello, I am using a VARIANT to pass an IDispatch pointer into a collection class I got from the net. When the dispatch is put into the variant it seems to be calling AddRef() on the dispatch pointer. Is this normal? I know this is the problem because a quick cal to Release() on the pointer just after the VARIANT is created solves the problem.
Phil Da Lick! wrote: > I am using a VARIANT to pass an IDispatch pointer into a collection > class I got from the net. When the dispatch is put into the variant it > seems to be calling AddRef() on the dispatch pointer. Is this normal? VARIANT is a plain C structure. It's not calling anything on anything - it does not have any code. _You_ must AddRef a pointer that you place into VARIANT. > I know this is the problem because a quick cal to Release() on the > pointer just after the VARIANT is created solves the problem. What problem? -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Igor Tandetnik wrote: > Phil Da Lick! wrote: > >>I am using a VARIANT to pass an IDispatch pointer into a collection >>class I got from the net. When the dispatch is put into the variant it >>seems to be calling AddRef() on the dispatch pointer. Is this normal? > > > VARIANT is a plain C structure. It's not calling anything on anything - > it does not have any code. _You_ must AddRef a pointer that you place > into VARIANT. Weird. Guess I'll have to have a closer look. >>I know this is the problem because a quick cal to Release() on the >>pointer just after the VARIANT is created solves the problem. > > > What problem? The problem of one of my objects (the one being stored as a dispatch in a variant in a collection) not being freed.
"Phil Da Lick!" wrote in message news:43bf066d$0$82643$ed2619ec@ptn-nntp-reader03.plus.net > Igor Tandetnik wrote: >> What problem? > > The problem of one of my objects (the one being stored as a dispatch > in a variant in a collection) not being freed. Somewhere you are not maintaining reference count correctly. Throwing AddRef's and Releases into the code at random in hopes the problem goes away might not be the best strategy. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925