Gargage Collector and VO->X#-Conversion
Posted: Tue Nov 29, 2016 12:24 pm
I still have many problems with correct cleaning up ressources. When analyzing the problems I came accross that already in VO the source code was not always correct (the source code that I had written on my own or that I had collected from different programmers). Here is what I have understood until now:
VO:
- Registeraxit (self) tells the garbage collector that an own method AXIT must be called to clean up additional ressources as file handles, SQL objects, ... that are not standard dynamic memory variables as strings, objects....
- In case that a close method called from the program calls "Unregisteraxit(self)" then the AXIT method does not have to be called anymore because all cleaning has already been made.
- UnregisterAxit in the AXIT method does not make any sense because unregisteraxit should be used to avoid calling AXIT
DOTNET:
- RegisterAxit is not needed, having a destructor (previous AXIT) is sufficient for the runtime to know that there is a method to be called for cleaning.
- The destructor is not similar to the C++-destructor and should only be used if necessary. It should only clean up ressources like file handles, SQL objects.
- the destructor needs additional ressources and prevents cleaning up objects quickly when having to call the destructor. Therefore similar to VO UnregisterAxit(self) or gc.suppressfinalizer(self) can be called in a close method called from the program.
- In contrast to VO the DOTNET garbage collector is called in another program thread parallel to the program execution. This makes the program execution much faster, but can give errors if ressource usage as ODBC is not threadsafe or when accessing global objects.
- Microsoft recommends using the IDISPOSABLE interface for cleaning up ressources. This seems to be mainly for having implementation rules and does not resolve directly correct cleaning up of ressources.
VO and DOTNET:
- Both, VO and Dotnet, have advantages if close methods are called by the programmer if possible: Ressources are released immediately, runtime errors in the close method appear in the normal thread and can be detected easier.
- Both, VO and Dotnet have advantages to limit access to external ressources like files/databases to few program parts and try to handle logical processess only using standard variables as string/objects.
VO:
- Registeraxit (self) tells the garbage collector that an own method AXIT must be called to clean up additional ressources as file handles, SQL objects, ... that are not standard dynamic memory variables as strings, objects....
- In case that a close method called from the program calls "Unregisteraxit(self)" then the AXIT method does not have to be called anymore because all cleaning has already been made.
- UnregisterAxit in the AXIT method does not make any sense because unregisteraxit should be used to avoid calling AXIT
DOTNET:
- RegisterAxit is not needed, having a destructor (previous AXIT) is sufficient for the runtime to know that there is a method to be called for cleaning.
- The destructor is not similar to the C++-destructor and should only be used if necessary. It should only clean up ressources like file handles, SQL objects.
- the destructor needs additional ressources and prevents cleaning up objects quickly when having to call the destructor. Therefore similar to VO UnregisterAxit(self) or gc.suppressfinalizer(self) can be called in a close method called from the program.
- In contrast to VO the DOTNET garbage collector is called in another program thread parallel to the program execution. This makes the program execution much faster, but can give errors if ressource usage as ODBC is not threadsafe or when accessing global objects.
- Microsoft recommends using the IDISPOSABLE interface for cleaning up ressources. This seems to be mainly for having implementation rules and does not resolve directly correct cleaning up of ressources.
VO and DOTNET:
- Both, VO and Dotnet, have advantages if close methods are called by the programmer if possible: Ressources are released immediately, runtime errors in the close method appear in the normal thread and can be detected easier.
- Both, VO and Dotnet have advantages to limit access to external ressources like files/databases to few program parts and try to handle logical processess only using standard variables as string/objects.