[]cse: Object Refrence Count

General discussions related to using the C# Script Engine in APL+Win.

Moderators: Tech Support, phpbb_admin

[]cse: Object Refrence Count

Postby Ajay Askoolum » November 19th, 2013, 10:54 am

What does []cse 'Close' do?

Does it simply force a garbage collection? Or does it close each object (perhaps using an internal reference count) and hope that the garbage collection then does the rest, as and when?
Ajay Askoolum
 
Posts: 641
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: []cse: Object Refrence Count

Postby joe_blaze » November 19th, 2013, 10:17 pm

H Ajay,

Thanks for posting this question about the action of the CSE 'Close' method.

When the CSE close method is executed, the instance of the CSE (which is a .Net object) is marked as 'Disposed'. In .Net an object marked as 'Disposed' will be handled by the .Net 'Garbage Collector' at a time determined by the virtual machine (Common Language Runtime CLR) on which .Net software is run. There is no reference counting done by the CSE because the CSE is an interface to the C# programming language which does not support reference counting. The CSE 'Close' method does not 'force' garbage collection'.

This means that, just as in a C# program created in Visual Studio, it is necessary for the programmer to properly dispose of certain .Net objects created in a C# program.
The 'detailed' example in the CSE documentation about using ADO.Net with the CSE points this out.
There are several ways to assure that .Net objects are properly disposed when a C# program ends, for example a using {...} statement (http://msdn.microsoft.com/en-us/library ... 2(v=vs.110).aspx).
Typically .Net objects such as Database connections, instances of ActiveX objects and file streams need to be properly disposed in .Net because they could affect other programs and users of those resources. .Net objects such as variables and instances of most .Net classes need not be disposed as this will 'automatically' happen when a C# program ends and those .Net objects cannot affect the permissions of other users.

Joe Blaze
joe_blaze
 
Posts: 383
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361


Return to APL+Win & The C# Script Engine

Who is online

Users browsing this forum: No registered users and 1 guest

cron