This might be fixed in the latest version of AJAX.NET, but we are using
the latest source release. It seems that when you call
"RegisterTypeForAjax", AJAX.NET Pro adds the javascript for the page to
a static hashtable, _keyed on the Page object_. In order to free this
memory, the code registers an event handler with the PreRender event of
the page.
This is a really bad plan! PreRender does not get called under the
following two conditions:
- An error occurs before PreRender
- A Response.Redirect occurs
and there are probably others.
We have a couple AJAX calls on our pages, and we often do server side
redirects to navigate upon post-backs. This was causing TONS of memory
to leak, since the entire ASP.NET page was pinned in memory by
AJAX.NET, and all of the various business objects that were referenced.
We worked around this using the following code, which is called before
a redirect and also during the OnError of our page base class:
Type type = typeof(Control);
FieldInfo handlersField = typeof(Control).GetField("_events",
BindingFlags.NonPublic | BindingFlags.Instance);
EventHandlerList events =
(EventHandlerList)handlersField.GetValue(curPage);
FieldInfo preRenderEventObjField =
typeof(Control).GetField("EventPreRender", BindingFlags.NonPublic |
BindingFlags.Static);
object preRenderEventObj = preRenderEventObjField.GetValue(curPage);
Delegate handler = events[preRenderEventObj];
foreach (Delegate dlg in handler.GetInvocationList()) {
// Fix for big memory leak due to AjaxPro
if (dlg.Method.DeclaringType.ToString().ToLower().IndexOf("ajaxpro")
>= 0 &&
dlg.Method.Name.ToLower().IndexOf("prerender") >= 0) {
dlg.Method.Invoke(dlg.Target, new object[] { curPage, new
EventArgs()
});
}
}
This will fire the PreRender handler of AJAX.NET Pro regardless, and
free the memory. We noticed our app servers no longer crash half way
through the business day with OutOfMemoryErrors :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ajax.NET Professional" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/ajaxpro
The latest downloads of Ajax.NET Professional can be found at
http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---