Very very Big bug with SLExtension command.

Jun 1, 2009 at 5:27 AM

Hi all, I just found very big bug in slextesions. I thought i have done some mistakes but when i see the live example of slextension than i realized that it is a bug.

try this. http://www.slextensions.net/showcase/#Page=2

click on open button and than visit other link and than again comeback to this page(command service menu) and than  click on open button again, you can see the problem. the command will fire twice.

 

Please help......................

Coordinator
Jun 1, 2009 at 6:41 AM

Hello,

This not really a bug in Commanding. It's a memory leak in the showcase. When we are switching from a page to another we do not unregister static Command references introduced when linking page controls to commands. The best solution at this time is to unregister your commands when your page is removed by calling CommandService.UnregisterCommandsRecursive( yourPage ).

Thierry

Jun 1, 2009 at 9:25 AM

Hi Titaye, thanks for the reply, can you please tell me where i can write CommandService.UnregisterCommandsRecursive( yourPage ) ?

 

Thanks again

Jun 9, 2009 at 7:40 AM

Please help

Coordinator
Jun 9, 2009 at 8:39 AM
Edited Jun 9, 2009 at 8:56 AM

Hello,

I was quite busy, I’m sorry about the delay.

I was wrong with my first answer. I’ve debugged the showcase and committed the bugfix in the showcase. The bug is that the PageCommandController initialized in the PageCommand is subscribing to  TestCommands.OpenCommand.Executed

As TestCommands is static, the controller was still hooked to this event even if the page was changed.

I’ve implemented the IDisposable interface in PageCommandController and in the Dispose method I’m now unsubscribing from this event.

#region IDisposable Members
public
void Dispose()
{

    TestCommands
.OpenCommand.Executed -= new EventHandler<ExecutedEventArgs>(OpenCommand_Executed);
}

#endregion

I’ve also implemented the IDisposable interface un the PageCommand where I launch the Dispose method of my controller.

#region IDisposable Members
public void Dispose()
{

    IDisposable
disposable = Resources["controller"] as IDisposable;
    disposable
.Dispose();
}

#endregion

In the ShowCaseController that is dealing with the page to be shown, I now Dispose the Pages implementing the IDisposable interface.

public object CurrentPage
{

    get
{ return currentPage; }
    set

    {

       if
(currentPage != value)
       {

            IDisposable
disposable = currentPage as IDisposable;
            if
(disposable != null)
            {

                disposable
.Dispose();
            }

            currentPage
= value;
            this
.OnPropertyChanged(this.GetPropertyName(n => n.CurrentPage));}}      
       }
    }
}

Thierry

Jun 10, 2009 at 6:45 AM

Thanks Thierry for the idea, I am trying on it. i will let you know the result :)

Jun 11, 2009 at 7:30 AM

Thanks, it's working...