Archive for 'Technology'
SPLimitedWebPartManager Memory Leak?
Posted on 05. Jun, 2007 by bryan.
Have a look at the following code segment:
while(true) { using (SPSite siteCollection = new SPSite("http://localhost")) using (SPWeb site = siteCollection.OpenWeb("/Marketing")) { SPFolder pagesFolder = site.GetFolder("Pages"); foreach (SPFile page in pagesFolder.Files) { WL(page.Url); using (SPLimitedWebPartManager webPartManager = page.GetLimitedWebPartManager (PersonalizationScope.Shared)) { } } } }
With this code segment I’m just connecting to a site and iterating over the page collection, grabbing and instance of the page’s SPLimitedWebPartManager as I go. Since SPLimitedWebPartManager implements the IDisposable pattern I am being a good citizen and wrapping its instantiation in a using {} block. The problem with this code segment is that this is what it does to the process memory:
Now, if I change the source code to this:
while(true) { using (SPSite siteCollection = new SPSite("http://localhost")) using (SPWeb site = siteCollection.OpenWeb("/Marketing")) { SPFolder pagesFolder = site.GetFolder("Pages"); foreach (SPFile page in pagesFolder.Files) { WL(page.Url); using (SPLimitedWebPartManager webPartManager = page.GetLimitedWebPartManager (PersonalizationScope.Shared)) { webPartManager.Web.Dispose(); } } } }
The memory picture looks much different now:
The only difference being the addition of an explicit Dispose() within the webPartManager using.
A look inside the SPFile.GetLimitedWebPartManager call reveals that it calls an internal GetLimitedWebPartManagerInternal() method on the SPFile SPWeb member variable. A closer look at this method shows the following code:
SPWeb web = this.Site.OpenWeb(); if (this.AllowUnsafeUpdates) { web.AllowUnsafeUpdates = this.AllowUnsafeUpdates; } SPWebPartManager manager = web.GetWebPartManagerInternal(pageUrl, requestedView, forRender, includeHidden, out bytes);
We see here that a new SPWeb object is getting spun up, and in the call to GetWebPartManagerInternal an assignment is going to be made to the SPLimitedWebPartManager m_web member variable. If we look at the Dispose() implementation for SPLimitedWebPartManager, we see the following:
public void Dispose() { if (!this.m_disposed) { if (this.m_manager != null) { this.m_manager.Dispose(); } } else { return; } this.m_webParts = null; this.m_manager = null; this.m_disposed = true; }
Nothing is being done to dispose of the m_web! If I explicitly dispose of m_web, then memory stays low.
Is anyone encountering the same?
Continue Reading
Exporting DataView with Custom Parameter
Posted on 30. May, 2007 by bryan.
This past week I have been working with a DataView that needed to filter a list by the title of the PublishingPage containing the DataView web part. In order to provide this functionality, I created a straight-forward custom parameter:
public class PageTitleParameter : System.Web.UI.WebControls.Parameter
{
protected override object Evaluate(System.Web.HttpContext context, System.Web.UI.Control control)
{
SPListItem listItem = SPContext.Current.ListItem;
if (listItem != null)
{
try
{
return listItem.Title;
}
catch
{
return string.Empty;
}
}
return string.Empty;
}
}
Creating custom Parameters has been covered elsewhere, so I won’t bother going into that, it works pretty much the same in SharePoint as in any ASP.NET application. Where things get different, is after you export your shiny-new DataView web part to SharePoint. If your experience is anything like mine, when you add your web part to a page instead of seeing your rendered DataView, you see “Parsing Error: Object reference not set to an instance of an object”.
So what went wrong? If you look carefully at the parser error, you will likely see that the TagPrefix that you setup when you registered your custom parameter in SharePoint Designer has been replaced with something like “cc3”, “cc4”, etc. In order to fix this, instead of exporting the web part from SPD straight into SharePoint, save it to a file first. Open the .webpart file that you saved and add your @Register directive for “cc3” or “cc4” or whatever your custom parameter’s TagPrefix happened to become. You can now go into the Web Part Gallery and upload your web part.
Good luck!
Continue Reading
Running ASP.NET app within a SharePoint Virtual Server
Posted on 29. May, 2007 by bryan.
For my own development efforts, I use Axosoft’s OnTime product which is free for a single user (yeah!). I have a single SSL for Axosoft and for my WSS Team Site installation, so I needed for both to coexist peacefully in a single virtual server. Out of the box Axosoft was throwing several errors, at which point I came across this link from Microsoft:
How to enable an ASP.Net application to run on a SharePoint virtual server
After completing the steps in the article OnTime began working flawlessly! Nice!
Continue Reading
Just When You Thought You Knew RDP …
Posted on 23. May, 2007 by bryan.
So you have probably used RDP about 5.1 gajillion times, but then you learn something new that shakes your foundation. Well that is what happened to me this past week when I learned 2 new things with RDP, and I am not ashamed to admit it either! Here goes nothing:

What we are looking at here are the command line parameters for MSTSC.EXE, our beloved RDP client. The 2 that jumped out to me this week were /span and /console. /span allows you to have a fullscreen RDP session that spans multiple monitors (difficult one for a screen shot, sorry folks!). The other, /console, allows you to connect to the console session (session 0) on the system, which as you can note above is only possible for Server 2003.
Hmm.. Alright, I confess, maybe it’s 3 things I picked up on this week. Last, but not least (actually probably my favorite for day-to-day), is that there was a Remote Desktops MMC plug-in that snuck into Windows Server 2003. Have a look:

What we have here is the ability to define various RDP server connections, and the connections will actually appear in the view pane. You can then click between the various servers and have it appear in the view pane. This makes it very simple to switch between multiple RDP sessions.
In order to get the Remote Desktops MMC you need to install the ADMINPAK.MSI from the SYSTEM32 folder of a Windows Server 2003.

