Custom Business objects question

  • Thread starter Yankee Imperialist Dog
  • Start date
Y

Yankee Imperialist Dog

I'm creating a lot if custom business objects. They work better, faster and
lighter than using table adaptors. Totally cool so far except for one thing i
just thought of: destructors. I've searched for this a little and can not
find a good answer as to whether or not to create them nor how to use them. I
kill all my datareaders (like a good boy should!), but i'm starting to get
concerned about these custom objects and lists of objects i'm creating.

1. I'm doing asp.net if it makes a difference
2. i get the impression that they just die when they go out of scope.
3. if they do die when out of scope can the garbage collector be told to
free up.
space now?
4. It's worth noting that all my created object are dumb objects that do not
include methods. Methods are in other classes. This does make them light, so
should i be worried?
Thanks
 
M

Marc Gravell

1. I'm doing asp.net if it makes a difference

Not really; the main things that make a difference are whether you are
talking to unmanaged resources, such as handles or COM. If you aren't
doing this, you don't need a finalizer (aka destructor, but finalizer
is the official term for .NET). If you *were* holding an expensive
resource, then IDisposable would be a good idea, but you don't it just
for domain entities (data classes).
2. i get the impression that they just die when they go out of scope.

They become eligible for garbage collection (assuming you haven't
linked them somewhere). When they are collected is non-deterministic,
but if they are short-lived (typical for ASP.NET) they will be in
"generation zero", where they can be collected very efficiently;
the .NET garbage collector assumes that most objects are short-lived,
and is designed to exploit this.
3. if they do die when out of scope can the garbage collector be told to
free up space now?

Yes, but don't. Let the GC alone - it knows what it is doing.
4. It's worth noting that all my created object are dumb objects that do not
include methods. Methods are in other classes.  This does make them light, so
should i be worried?

That doesn't make them any lighter or heavier in terms of memory usage
- so this isn't an issue.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top