For Programmers: Reduce Your Graph Data Provider's Memory Usage

Jun 11, 2012 at 7:08 PM
Edited Jun 12, 2012 at 12:10 AM

If you are a programmer and you have created a NodeXL graph data provider, you can make a small change to your provider that might significantly reduce the amount of memory it uses.  Many users of the built-in Twitter, Flickr and YouTube providers have reported OutOfMemoryException errors, and if your users have encountered these errors, too, then you should consider making this change.

You are not required to change anything in your provider.  NodeXL will continue to work with older providers if you decide not to modify yours.

To modify your graph data provider to use less memory:

1. Download the latest NodeXL Class Libraries from the NodeXL Downloads tab at http://nodexl.codeplex.com/releases.  You need version number 1.0.1.215 or later.

2. Reference the new Microsoft.NodeXL.ExcelTemplatePlugIns.dll assembly in your graph data provider project.

3. Derive your graph data provider class from IGraphDataProvider2 instead of IGraphDataProvider.  Change this:

    public class MyGraphDataProvider : IGraphDataProvider

to this:

    public class MyGraphDataProvider: IGraphDataProvider2

4. Replace your TryGetGraphData() method with TryGetGraphDataAsTemporaryFile().  Change this:

    public Boolean TryGetGraphData(out String graphDataAsGraphML)

to this:

    public Boolean TryGetGraphDataAsTemporaryFile(out String pathToTemporaryFile)

5. Return your GraphML in a temporary file instead of as a string.  Change this:

    graphDataAsGraphML = xmlDocument.OuterXml;

to this:

    pathToTemporaryFile = System.IO.Path.GetTempFileName();
    oXmlDocument.Save(pathToTemporaryFile);

6. Test your updated provider with the latest version of the NodeXL Excel Template.

Note that if you derive your class from IGraphDataProvider2 instead of IGraphDataProvider, as I'm recommending here, your updated provider will not work with older versions of NodeXL.  If you want your updated provider to work with both old and new versions of NodeXL, you can implement both IGraphDataProvider and IGraphDataProvider2, in which case older versions of NodeXL will continue to use your IGraphDataProvider implementation, while newer versions will use your IGraphDataProvider2 implementation.

-- Tony