.NET controls dispose in Dyalog

Using (or providing) Microsoft.NET Classes
Post Reply
Alexey
Posts: 6
Joined: Wed Dec 01, 2010 1:15 pm

.NET controls dispose in Dyalog

Post by Alexey »

Most of the .NET GUI objects/controls must be explicitly disposed at the end. In traditional environments (like C#, for example) it is the IDE (like MS Visual Studio) that counts the controls and adds appropriate code to the project to get the controls disposed.
When using .NET GUI stuff in Dyalog APL it is annoying to take care about every single .NET control and object, … and as far I understood it is not enough just to delete all references to GUI object in the APL workspace.

The question: is there a method (in Dyalog APL) to dispose all .NET GUI controls used by an application at once?

Without such cleanup it can be very problematic to re-run an APL application with .NET GUI without reloading the workspace.
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: .NET controls dispose in Dyalog

Post by PGilbert »

Dyalog would expand more on the subject but I run the function 'CloseAppDomain' each time before I start a large .Net function to clean-up .Net from the previous run. It is available also Under File-> Close AppDomain. We put some indication ('Closing AppDomain' and 'AppDomain Closed') because it could take quite long to execute when there is many .Net objects loaded. To be used in development mode so you don't need to Reload the WS each time you want to run your main function, in Run Time mode it is not necessary like you said.

Code: Select all

 CloseAppDomain
 'Closing AppDomain'
 1 ⎕NQ'⎕SE.mb.file.closead' 'Select'
 'AppDomain Closed'
User avatar
JohnD|Dyalog
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: .NET controls dispose in Dyalog

Post by JohnD|Dyalog »

Closing the AppDomain is the only way to do this at the moment. I think that calls Dispose on everything it needs to - the documentation http://msdn.microsoft.com/en-us/library/aw58wzka(v=vs.110).aspx says that Finalize will call Dispose() - and Finalize should be called when the AppDomain is discarded.

I'm not sure that it's true that "it is the IDE (like MS Visual Studio) that counts the controls and adds appropriate code to the project to get the controls disposed". Certainly if you use the "using" statement in C# (http://msdn.microsoft.com/en-us//library/yh598w02.aspx) then Dispose is called for you but I don't think that it is done without "using".

There is an argument for something like C#'s using in Dyalog, but we haven't thought it through yet.

Best Regards,
John Daintree.
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: .NET controls dispose in Dyalog

Post by PGilbert »

On a long running function we like to 'Dispose' the MemoryStream (ms) by doing:

Code: Select all

ms.Close ⋄ ms.Dispose ⋄ ms←⎕NULL


when the memory Stream is large and using a lot of memory this is a good way to release it's memory before the end of the application. It is said that for the garbage collector to reclaim the memory it is necessary to 'unreference' the memory stream (by doing ms←⎕NULL), the .Dispose method is not enough.

With Window Form (WF) most of the controls have a .Dispose method to use, but with Window Presentation Foundation (WPF) there is almost none, and there is stuff like the Memory Stream that is used by WF and WPF that has a .Dispose method. Should we ABSOLUTELY use the .Dispose method when there is one available or the garbage collector will do its job anyway even if we don't use the .Dispose method ? (Question for Dyalog)

Thanks
Alexey
Posts: 6
Joined: Wed Dec 01, 2010 1:15 pm

Re: .NET controls dispose in Dyalog

Post by Alexey »

Thank you, gentlemen. Very helpful.
Post Reply