EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Disposal of CallbackFileSystem

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
Posted: 01/14/2009 21:06:39
by Vladimir Tcherkacheninov (Basic support level)
Joined: 11/02/2007
Posts: 11

In my application, I create number of CallbackFileSystem objects and eventually it would stop working properly. Investigating, I found that those objects dont get garbage collected. Looking at the memory heap in Windbg, I see that there is a reference to those objects:

0:015> !gcroot 012a8134
Note: Roots found on stacks may be false positives. Run "!help gcroot" for
more info.
Scan Thread 0 OSTHread 8a8
Scan Thread 2 OSTHread 308
Scan Thread 5 OSTHread 7c
Scan Thread 7 OSTHread ec0
Scan Thread 9 OSTHread 89c
Scan Thread 8 OSTHread 404
Scan Thread 11 OSTHread b8c
Scan Thread 12 OSTHread 9a0
Scan Thread 13 OSTHread 904

I created a project to demonstrate this problem. This sample project is your VMounter project with gui staff removed. My app exhibits same behavior and it is always CbFsCloseEnumerationEvent.

[ Download ]
Posted: 01/15/2009 00:50:42
by Volodymyr Zinin (EldoS Corp.)


Please specify what version of CallbackFS and what Windows version (including whether it's 32 or 64 bit) are you using?
Posted: 01/15/2009 07:04:32
by Eugene Mayevski (EldoS Corp.)

Can you please explain what exactly objects are not disposed of? also did you run any profiler on your code? see try with AQTime a bit later

Sincerely yours
Eugene Mayevski
Posted: 01/15/2009 08:42:37
by Vladimir Tcherkacheninov (Basic support level)
Joined: 11/02/2007
Posts: 11

I am using CBFS v.2.1.43. both 32 and 64 bit has same problem.
If you look at the code I attached, VMounter should be eventually garbage collected. It never happens. I did not try AQTime, i use WinDBg with sos extension to look at CLR. An I see those objects never collected.

for (int i = 0; i < 100; i++)
VMounter mounter = new VMounter();
string mountpoint = "D:\\Temp\\Test";
Console.WriteLine("Test done.");

Will try some more test with profiler
Posted: 01/15/2009 08:49:35
by Vladimir Tcherkacheninov (Basic support level)
Joined: 11/02/2007
Posts: 11

Did some quick test with Microsoft CLRProfiler and if I dont create CbFsCloseEnumerationEvent event, everything collected properly. How impotent to create this event and if I dont, would Enumeration be closed and cleaned in cbfs driver.
Posted: 01/15/2009 11:41:44
by Eugene Mayevski (EldoS Corp.)

Thank you for details. They will help us do the tests quicker.

OnCloseEnumeration is used to let the application clean up the memory, that could have been allocated for enumeration.

We have the following code in the sources:

        GCHandle gch1, gch2;
        gch2 = GCHandle::FromIntPtr((IntPtr)Ccb->UserContext);

        EnumerationInfo = (CbFsEnumerationInfo^)gch2.Target;
            Self->OnCloseEnumeration(Self, FileInfo, (IntPtr)EnumerationInfo->EnumerationContext);
            Self->OnCloseEnumeration(Self, FileInfo, (IntPtr)EnumerationInfo->StreamEnumerationContext);
        Ccb->UserContext = NULL;


As you can see, the only difference between assigning and not assigning the event handler is a typecast to IntPtr. Can it make difference? I don't know at the moment - we are not experts in .NET internals (we focus more on Win32). This needs to be investigated and will be done tomorrow.

Sincerely yours
Eugene Mayevski
Posted: 01/16/2009 11:35:31
by Eugene Mayevski (EldoS Corp.)

Actually your code won't add a mounting point. You can't pass a folder as a mounting point. So any further tests make no sense. I have noticed this just now after I have run your sample.
Posted: 01/16/2009 13:47:29
by Vladimir Tcherkacheninov (Basic support level)
Joined: 11/02/2007
Posts: 11

It doesnt. I dont event have key there. But it behaves same way when everything works. My point is when object goes out of context it should be garbage collected. In this case it doesnt because of CbFsCloseEnumerationEvent being referenced somewhere in your code and doesnt get disposed. I will fix my sample to work properly.
Posted: 01/16/2009 13:52:33
by Vladimir Tcherkacheninov (Basic support level)
Joined: 11/02/2007
Posts: 11

As I said in my previous reply if I don create CbFsCloseEnumerationEvent event like:

mCbFs.OnCloseEnumeration=new CbFsCloseEnumerationEvent(CbFsCloseEnumeration);

then after your run this with CRLProfiler, you would not see VMounter and CallbackFS.CallbackFileSystem objects.
Posted: 01/16/2009 14:36:53
by Eugene Mayevski (EldoS Corp.)

The key has been omited, I noticed this. But debugging a non-functioning application makes little sense initially - the code should work in correct conditions, then we can move to various scenarios of incorrect use. Nevermind, when running the fixed sample I have come across the weird behavior (AllocationSize is set to meaningless values like ~4 bln) which needs to be investigated by driver developers. Once we solve this problem, I'll move further with your test. So far AQTime just hangs on your sample, so I can't do anything.

Regarding your comment - I have posted the code in CBFSNet module, which is the only one that calls OnCloseEnumeration. This means that whatever influences garbage collecvtion is located within the posted lines of code.

Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.



Topic viewed 10096 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!