Page 1 of 1
.NET controls dispose in Dyalog
Posted: Mon Apr 21, 2014 1:29 pm
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.
Re: .NET controls dispose in Dyalog
Posted: Tue Apr 22, 2014 8:11 pm
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'
Re: .NET controls dispose in Dyalog
Posted: Wed Apr 23, 2014 12:31 pm
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.
Re: .NET controls dispose in Dyalog
Posted: Fri Apr 25, 2014 12:13 am
by PGilbert
On a long running function we like to 'Dispose' the MemoryStream (ms) by doing:
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
Re: .NET controls dispose in Dyalog
Posted: Fri Apr 25, 2014 6:46 am
by Alexey
Thank you, gentlemen. Very helpful.