C
Cordell Lawrence \(News Group\)
There an ongoing discussion between a colleague and myself about the
usefulness of the IDisposable pattern beyond the reclamation of unmanaged
resources. The discussion is somewhat lengthy so I will distill it here.
The core of his argument started with his statement:
"There is no gain in performance, maintainability or otherwise by
implementing the Dispose method if unmanaged resources are not involved."
I focused particularly on the "unless unmanaged resources are involved."
rather than on "No gain in performance" ... Maintainability is a arguable
point. My thinking is that the pattern can be useful for state maintenance
issues at the end of an object's lifetime and not necessarily related to
memory reclamation.
My counter argument was based on the implementation of the
System.Transactions.TransactionScope type in the .Net 2.0 BCL that
essentially defers the execution of the Rollback or Commit of the
Transaction* (as well as context maintenance of the ambient Transaction) to
the Disposal of the scope instance. They chose not to design the type with
BeginScope() and EndScope() methods but instead used the dispose pattern. I
also point out the article by Stephen Toup and his use of IDisposable in his
Scope<T> type. Of course I went into a lot more detail there. The entire
discussion between us was quite interesting and I have no problems posting
it if anyone out there would like to read it.
I ended my first rebuttal with the following paragraph:
"Instances of System.Transactions.Transaction types may be elevated from LTM
transactions to Enterprise Services DTC Transactions that utilize unmanaged
resources that may need to be reclaimed. Quite apart from this fact though,
the implementation of the TransactionScope type and it's affinity to and
reliance on the dispose pattern for the proper execution of its core
function, unrelated to unmanaged resources or the deterministic reclamation
of those resources most clearly illustrates my point that the Dispose
Pattern's usefulness can exceed memory management."
I just wanted to get feedback from the community about there thoughts on
this?
Cordell Lawrence
Teleios Systems Ltd.
usefulness of the IDisposable pattern beyond the reclamation of unmanaged
resources. The discussion is somewhat lengthy so I will distill it here.
The core of his argument started with his statement:
"There is no gain in performance, maintainability or otherwise by
implementing the Dispose method if unmanaged resources are not involved."
I focused particularly on the "unless unmanaged resources are involved."
rather than on "No gain in performance" ... Maintainability is a arguable
point. My thinking is that the pattern can be useful for state maintenance
issues at the end of an object's lifetime and not necessarily related to
memory reclamation.
My counter argument was based on the implementation of the
System.Transactions.TransactionScope type in the .Net 2.0 BCL that
essentially defers the execution of the Rollback or Commit of the
Transaction* (as well as context maintenance of the ambient Transaction) to
the Disposal of the scope instance. They chose not to design the type with
BeginScope() and EndScope() methods but instead used the dispose pattern. I
also point out the article by Stephen Toup and his use of IDisposable in his
Scope<T> type. Of course I went into a lot more detail there. The entire
discussion between us was quite interesting and I have no problems posting
it if anyone out there would like to read it.
I ended my first rebuttal with the following paragraph:
"Instances of System.Transactions.Transaction types may be elevated from LTM
transactions to Enterprise Services DTC Transactions that utilize unmanaged
resources that may need to be reclaimed. Quite apart from this fact though,
the implementation of the TransactionScope type and it's affinity to and
reliance on the dispose pattern for the proper execution of its core
function, unrelated to unmanaged resources or the deterministic reclamation
of those resources most clearly illustrates my point that the Dispose
Pattern's usefulness can exceed memory management."
I just wanted to get feedback from the community about there thoughts on
this?
Cordell Lawrence
Teleios Systems Ltd.