--- In [email protected], "brucexs" <bruc...@...> wrote: > > > > I don't really understand the situation.
> How does handle number relate to ref count? It means that a handle isn't being freed. Second time into script, c\0x05_003 should be free, but it's not, plugin uses next free hanlde, so c\0x05_004. Next time I call script, c\0x05_003 and c\0x05_004 not free, so plugin allocates c\0x05_004. Something's not getting freed each time scriptlet is called. This is only the case if my script includes a for each loop (which I can tell by running any other script repeatedly and watching the handle numbers not increase from run to run). I'll run everything in debugger some more and see if I can get any more exact diagnosis. I'm working with dll in comPlugin0.73_100407RefCounting.zip, at http://tech.groups.yahoo.com/group/power-pro/files/0_TEMP_/AlansPluginProvisional/ sample script there too. > More comments below, but can I suggest you try a test without for each > something like. > > local objFile > local hCollectionFiles = objFolder.Files > objfile =hCollectionFiles.getnext //I don;t know right service > //include trace or win.debug(..._refs__) in your plugin to see if ref count > is incremented or win.debug on refs > > > > > > > > > > > local objFile > > > > local hCollectionFiles = objFolder.Files > > > > for each objFile in hCollectionFiles > > > > win.debug(" com handle: " ++ objFile ++ " ref cnt: " ++ > > > > objFile._refs__ ++ ", name: " ++ objFile.Name) > > > > endfor > > > > objFile = "" > > > > hCollectionFiles = "" > > Is the output you are showing in full note related to the win.debug > statement. It looks different? > > In any event, here is what I think should happen. > > 1. objFolder.files creates a new handle. Plugin sets its reference count to > zero. > > 2. Assignment to hCollectionFiles cases powerpro.exe to call your > refcallback(...,1) and you increment that handle's ref count to 1. > > 3. for each initialization calls plugin's foreach callback with variable > ""objFile" and the handle in hCollectionFiles. Plugin generates a handle > representing first item in enumeration, sets its ref count to zero, and call > setvar to assign it to objfile. after return for for each, foreach processor > calls your refcallback(...,1) to add reference to this handle. > > 4. For each subsequent iteration in the loop, foreach processor calls you > with "objFile". Plugin calls setvar. That will call your free callback on > the old handle value in objFile, which will decrement its ref count. Its ref > count will now be zero and that old value is released. Then after you return > from your foreach routine, PowerPro call will your refcallback(...,1) to add > a ref to new handle, making its ref count 1. > > 5. Note that, at end of for loop, ref count to last item returned in > enumerator is still 1 and that it's handle is in objFile. > > 6. Assignment of "" to objFile should call your free callback on that last > handle value, causing its ref count to go to zero and it to be released by > your plugin. > > 7. Assignment of "" to hCollectionFiles should call free callback for that > handle, causing its ref count to go to zero and you to release it. > Can you insert trace code or run under debugger to see if that is how your > plugin is being called for for each processing? Yes, will do. Also posted current com.dll and a sample script
