Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

DSL: ModelBusAdapters are created but not disposed

$
0
0

We're developing a Visual Studio toolkit (vsix add-in) with Domain Specific Languages for Visual Studio Ultimate 2010 on Windows 7.  The code is in C#.

The toolkit uses the ModelBusAdapters to communicate between model elements.  There seems to be a memory leak with the ModelBusAdapters.  The tool creates a ModelBusAdapter for each DSL file - hundreds in total.  The ModelBusAdapters don't seem to be disposed property when we're done with them.  Using the Task Manager, I can see the memory go up a few MB with every DoCreateAdapter call, but it never goes down.  We eventually run out of memory and crash.

Any advice to clean up this memory problem would be appreciated.

A portion of the code is below.

The code creating the adapters for each file element:

                    // Synchronize the message set with all the maps.                    foreach (string messageMapFileName in messageMapFileNamesAsList)                    {                        if (File.Exists(messageMapFileName))                        {                            using (IMessageMappingAdapter messageMappingAdapter = this.MessageMappingAdapterManager.CreateAdapter(messageMapFileName))                            {                                messageMappingAdapter.ServiceProvider = this.ServiceProvider;                                messageMappingAdapter.SynchronizeMessageSet(importMessageSet);                            }                        }                    }

The CreateAdaptor method:

        public IMessageMappingAdapter CreateAdapter(string mapPathAndFile)        {            if (string.IsNullOrEmpty(mapPathAndFile))            {                throw new ArgumentNullException("mapPathAndFile");            }            this.SetDTE();            if (this.dte != null)            {                EnvDTE.ProjectItem mapFile = this.dte.Solution.FindProjectItem(mapPathAndFile);                if (mapFile != null)                {                    // Since this method is called from Guidance there is no ModelBus so we must create one and register it with this Adapter Manager                    IModelBus modelBus = (this.CurrentModelBus == null) ? Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SModelBus)) as IModelBus : this.CurrentModelBus;                    if (modelBus != null)                    {                        ModelBusAdapterManager modelBusAdapterManager = modelBus.GetAdapterManager(MessageMappingAdapterBase.AdapterId);                        if (modelBusAdapterManager != null)                        {                            ModelBusReference modelBusReference = modelBusAdapterManager.CreateReference(mapFile);                            if (modelBusReference != null)                            {                                MessageMappingAdapter adapter = this.CreateAdapter(modelBusReference) as MessageMappingAdapter;                                if (adapter != null)                                {                                    return adapter;                                }                            }                        }                    }                }            }            return null;        }

Where we use the DoCreateAdapter method of Microsoft.VisualStudio.Modeling.Integration.Shell.VsModelingAdapterManager:

protected override DslIntegration::ModelBusAdapter DoCreateAdapter(DslIntegration::ModelBusReference reference, global::System.IServiceProvider serviceProvider)        {// If ModelBus is not null then we are running in VS so use the default implementation            if (this.ModelBus != null)            {                return base.DoCreateAdapter(reference, serviceProvider);            }        }

Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>