Reshat Sabiq wrote:
        nsCOMPtr<nsICacheSession> cacheSession;
        ...
        nsCOMPtr<nsICacheEntryDescriptor> cacheEntry;
        result = cacheSession->OpenCacheEntry(abc, sICache::ACCESS_READ,
PR_TRUE,  getter_AddRefs(cacheEntry));
        if (NS_FAILED(result))
        {
                cacheSession = nsnull; // is this necessary? if yes, i should 
do it
for cacheEntry as well

It's not necessary, no.

                result = cacheService->CreateSession("image",
nsICache::STORE_ANYWHERE,
                                         PR_TRUE,  getter_AddRefs
(cacheSession)); // if this assignment, and the one below release the
previous pointers, then = nsnull is unnecessary

|getter_AddRefs(cacheSession)| sets the nsCOMPtr to null as soon as you try to cast it to an nsICacheSession** (which is what this call does). So this code pattern is perfectly fine without manually setting to null.

                        nsISupportsVoid *wrapper;
                        componentManager->CreateInstanceByContractID
(NS_SUPPORTS_VOID_CONTRACTID, nsnull, NS_GET_IID(nsISupportsVoid),
(void**)&wrapper);

|wrapper| is a COM object like any other. You probably just want to use nsCOMPtr<nsISupportsVoid> for it....

is the following the right way to reclaim memory?
                        memoryManager->Free(wrapper);

No, since |wrapper| wasn't allocated by the memory manager... Like I said, it's just a refcounted object.

I.e., is memoryManager->Free(wrapper); the right way to do it, and will
it also Free the void * contained?

No, destruction of the nsISupportsVoid will not do anything with the void* (and can't, in fact, since it doesn't know what concrete class it is and hence whether any destructors need calling); you have to manually free that memory (using the memoryManager, since that's how it was allocated) and possiby manually call destructors (if your struct has any).

-Boris
_______________________________________________
Mozilla-xpcom mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to