memory leak?

Jan 21, 2011 at 12:18 PM

Hi ZiadJ. First thx for cool control.
But I have problem with memory. In current project I use prism and when I remove view with popupmenu from region it does not removed from memory by GC.It's because PopupMenuManager hold reference for MenuTriggerElement. Now I'm removing MenuTriggerElement from PopupMenuManager.ApplicationMenus manualy but it's be cool if you fix it.

Feb 3, 2011 at 11:42 AM

Hi i am having the same memory issue. I want to unregister those events when the popup menu gets closed, or when we change views. How can i do it? If you can pls elaborate, it would be usefull

Feb 3, 2011 at 5:50 PM

Hi. First I add helper method

public class PopupMenuManagerHelper
	{
		public static void UnrigesterPopupMenu(PopupMenu menu)
		{
			var result = PopupMenuManager.ApplicationMenus.Where(mte => mte.PopupMenu == menu).ToArray();
			foreach (var menuTriggerElement in result)
			{
				PopupMenuManager.ApplicationMenus.Remove(menuTriggerElement);
			}
		}
	}

next views that contain popup menu i marked with IDisposable interface and in Dispose method i unregister popup menu 

public partial class MyView : UserControl, IDisposable
	{
		#region Implementation of IDisposable

		public void Dispose()
		{
			PopupMenuManagerHelper.UnrigesterPopupMenu(pmMain);
		}

		#endregion
	}

And when I remove any view from region i run dispose method if removing view implements IDisposable :

public void RemoveViewFromMainRegion(string viewName)
		{
			var view = MainRegion.GetView(viewName);
			if (view != null)
			{
				MainRegion.Remove(view);

				if (view is IDisposable)
					((IDisposable)view).Dispose();
			}
		}

Feb 3, 2011 at 6:39 PM

Thanks a lot. i exactly required this to handle the memory issue that i was facing. Thanks a ton friend :)

Feb 5, 2011 at 7:08 PM

Another query:
In the xaml, i have defined a listbox as :

 

 <ListBox Name="lstPopupMenu" >
             <ctl:PopupMenuItem x:Name="pmiAddToCollection" Header="Add to collection                       &#9658;"  CloseOnClick="False" />
             <ctl:PopupMenuItem x:Name="pmiRemoveFromThisCollection" ImageSource="../Assets/Images/delete.png"  Tag="Remove from collection"  Header="Remove from collection"  MouseLeftButtonUp="MenuItem_Clicked" />
             <ctl:PopupMenuItem x:Name="pmiCopyToClipboard" Header="Copy to clipboard"  CloseOnClick="True" Tag="Copy to clipboard"  MouseLeftButtonUp="MenuItem_Clicked" /> 
</ListBox>
        
now in code behind i am creating a menu like this :

popUpMenu = new PopupMenu(lstPopupmenu){Orientation = MenuOrientationTypes.Right};
pouUpMenu.AddTrigger(TriggerTypes.RightClick, dgCenters);

Now, when i right click on my dgCenters grid, the poup opens, but i cant see the 3 items there. Only a small rectangle comes..but the menu items are not visible.

Can you point me, what i might be missing?
When i create menu/menuitem from code, without using listbox, the menu comes properly.

Thanks, in anticipation 
                                             
                                        

 

 

Feb 6, 2011 at 6:00 PM

OOPs..i had actually missed one style..got that working now. Thanks nevertheless

Feb 8, 2011 at 11:43 AM

There seems to be other huge leaks related to MouseEventHandlers. Anyone able to fix that?

Mar 7, 2011 at 2:30 AM

Please compile from the latest source code available from here:

http://sl4popupmenu.codeplex.com/SourceControl/list/changesets

I've added a deconstrutor which unregisters the menu from the PopupMenuManager.

As for the trigger element references the garbage collector friendly WeakReference type is being used in the MenuTriggerRelationship class.

I hope this fixes it.