Forum  General Visual ...  Visual WebGui v...  ComponentBase.Finalize
Previous Previous
 
Next Next
New Post 1/31/2012 6:02 AM
  globalservices
144 posts
5th Level Poster


ComponentBase.Finalize 

We are having a condtion in a large VWG-based application where, according to MS Support, the Finalizer thread triggers a GC and then is blocked waiting for the GC to complete.

The memory dumps we provided shows that Gizmox_WebGUI_Common!Gizmox.WebGUI.Forms.ComponentBase.Finalize() is trying to allocate a large object.

We know that it's bad practice to allocate objects during a Dispose, so we do avoid that. We also know that disposing of objects in our code rather than letting the GC do it for us is a best practice, so we do that where possible. Still, I see that we can have a half-million or more objects in our finalization queue, the large majority of which are of type Gizmox.WebGUI.Forms.ListViewItem.

My questions are:

1. Has anyone else run into this?

2. What other than doing little in Dispose and disposing of the objects that we can ourselves is recommended to avoid this?

3. I have the VWG 6.4 source code that I use for reference, but I don't see the code for ComponentBase in there. Is that available somewhere, or at least the Dispose/Finalize method code for it?

Thanks.

-Kelly

 

 
New Post 1/31/2012 8:24 AM
  globalservices
144 posts
5th Level Poster


Additional Info 
Modified By globalservices  on 1/31/2012 1:54:42 PM)

 As a follow-up, using SciTech .NET Memory Profiler attached to my w3wp.exe process running locally on IIS with no other sites running locally (i.e., only my usage of the site should be affecting memory), I can see that ListViewItems to which we attach right-click behavior are not removed from memory immediately when we call the ListView.Items.Clear method, which we do just before loading the next page of data or refreshing the current page. Similar LiveViewItems that do NOT have right-click behavior do seem to go away when ListView.Items.Clear is called.

The way we have right-click behavior implemented is to set the ListViewItem.ContextMenu property to a Gizmox...ContextMenu instance and also to wire an event handler to the ListViewItem.MenuClick event. I have added code to unhook the .MenuClick event prior to executing ListView.Items.Clear(), but that does not seem to allow these right-clickable (the only difference I can see from the ones that release properly) ListViewItem instances to be released when ListView.Items.Clear is called.

 
New Post 2/1/2012 7:22 AM
  globalservices
144 posts
5th Level Poster


Does ListViewItem.Dispose() call GC.SuppressFinalize(this)? 

Maybe a better way to ask the question is this. Does ListViewItem.Dispose() call GC.SuppressFinalize(this) at any point in the hierarchy?

I can't locate source code for RegisteredComponent or anything above it, so I can't know for sure.

What I can see is that, even if I unwire the .MenuClick event handler and call Dispose on each ListViewItem just before calling ListView.Items.Clear(), all of our ListViewItem instances still end up in the finalize queue.

That could be because GC.SuppressFinalize(this) is not called anywhere in the hierarchy -- typically, that would be called in a  Dispose() method with no parameters, which would then also call Dispose(true).

It can be for some other reason, but I'd like to rule out this one if someone at Gizmox with access to the source code could check and let me know please.

Thanks.

-Kelly

 

 
New Post 2/2/2012 8:47 AM
  ori.cohen
4390 posts
1st Level Poster




Re: Does ListViewItem.Dispose() call GC.SuppressFinalize(this)? 
Modified By ori.cohen  on 2/2/2012 12:48:15 PM)

Hello Kelly,

Impressive research!

The following is the inheritance construct of the Visual WebGui control:

SerializableObject -> ComponentBase -> RegisteredComponent -> Component -> Control

This is the content of the Dispose method of the 'ComponentBase' class:
public void Dispose()
{
    this.Dispose(true);
    GC.SuppressFinalize(this);
}


There is no call to a "Finalize" method anywhere in the above listed classes nor in any ListView related class.

I would greatly appreciate it if you could send us a sample application demonstrating this problematic scenario, so we can test it and resolve the problem.
Please send us your application to Support [at] VisualWebGui [dot] com with a link to this forum thread.
We would be willing to sign an NDA if necessary.
Please also clean the solution before compressing it and reply to this post after sending, with the subject of the e-mail you send, so I would know to check for your support request.

Regards,

Ori Cohen
Support Manager, the Visual WebGui team

 
New Post 2/2/2012 12:41 PM
  globalservices
144 posts
5th Level Poster


Re: Does ListViewItem.Dispose() call GC.SuppressFinalize(this)? 

 Thanks, Ori. I will work on a reproducible scenario ASAP.

Please note that you wouldn't see a call to any method named Finalize. Instead, if there were an explicit finalizer, it would be named like the constructor, but preceded by ~. So the finalizer, if there were an explicit one for, say, ComponentBase, would be a method named ~ComponentBase.

As I understand it, that method would only ever be called from the GC, and it's purpose would be to invoke Dispose(false) so that the object can be disposed, but (the false part) so that the dispose code knows to NOT try to dispose member objects that may no longer exist (no guaranteed order of cleanup at GC time). Ideally, the developer using the disposable object would call Dispose() when he/she is done (or put their code in a using() block) in which case as your code snippet shows, the object would get disposed, along with objects its managing, and then the object would be marked such that the GC would say "hey, this one already has been properly disposed, so don't put it in the finalization queue -- less work for me!"

In the absence of an explicit finalizer method, GC still will finalize IDisposable objects (if it hasn't been suppressed) by calling Dispose(false) - just no custom code would be executed in that condition (other than what's in Dispose(bool disposing) and not bracketed by if (disposing).

The call to GC.SuppressFinalize(this) is made to prevent GC from putting the object (this) in the queue for finalization. Obviously, that code exists (as you verified, thanks) in ComponentBase. If it were getting called, we shouldn't be seeing so many objects in our finalization queue.

One way for it NOT to be called would be having a Dispose() override anywhere in the chain that does not do a base.Dispose() call. I will look for that in our code, but so far have not seen it.

 
Previous Previous
 
Next Next
  Forum  General Visual ...  Visual WebGui v...  ComponentBase.Finalize
Azure banner
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS