Question about Book's "Disposing and Finalizing Objects"

Question about Book's "Disposing and Finalizing Objects"

Old forum URL: forums.lhotka.net/forums/t/340.aspx


willfarnaby posted on Sunday, June 11, 2006

Does this (see below) mean that if I have a field that contains, say, image data, then for all practical purposes I have to "modify the SimpleDataPortal class to explicitly call Dispose() on your business
objects on the server" ?

Quote:
-------

Disposing and Finalizing Objects

Implementing IDisposable

There are cases in which business objects can legitimately contain an expensive resource —
something like a multi-megabyte image in a field, perhaps.

In such cases, the business object should implement the IDisposable interface, which will allow the
UI code to tell the business object to release its resources. This interface requires that the object
implement a Dispose() method to actually release those resources.

Note: If you’re calling a remote data portal, you must avoid object designs that require IDisposable.
Alternatively, you can modify the SimpleDataPortal class to explicitly call Dispose() on your business
objects on the server.

DavidDilworth replied on Monday, June 12, 2006

I think the answer is two-fold.

(1) You should certainly consider implementing the IDisposable interface on your BO.  That way you have the ability to call the Dispose() method on your BO when required to free the resources used.

(2) Are you actually using a "remote data portal"?  If the answer to this question is yes, then I believe you should follow Rocky's advice.  However, it is quite possible that you are not using the fully remote Data Portal concept, so don't worry.

However, if you are using true remoting and have large image fields in your BO then are you really sure you want all that data being serialised and moved around the network?  Is there another way to achieve the same overall result by passing the URL/URI to the image instead?  Just a thought.

HTH

Copyright (c) Marimer LLC