Dave Burke - Freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

Class instantiation: use it or lose it. -- d.o.t.d.

It was a long time since I feared that I had really screwed up my app after deciphering an error message.  Here it is.  No stack information of assistance, no file info, no line number for the error. Just a worthless stackoverflow exception.  Errors are a way of life and they certainly don't bother me while I'm cranking out an app--as long as no one ever sees any after the app is released, of course.

I was able to track down the source of the error to a class component, which was instantiating a few other classes, as shown here:

  protected UtilsDB oUtilsDB = new UtilsDB();
  protected UBizUtils oUBizUtils = new UBizUtils(); 
  protected UtilsWeb oUtilsWeb = new UtilsWeb();

  
The problem was that I never used one of them in the class after creating it.  That was the source of the nasty, unusually difficult to track down problem.

The moral of the story--and discovery of the day--is that if you instantiate another class, use it...or lose it.  The app, that is.

Comments

Bill Rodenbaugh said:

Heres a fun way to make sure you are actually using what you instantiate.

private UtilsDB _UtilsDB;

protected UtilsDB oUtilsDB
{
get
{
if ( _UtilsDB; == null )
_UtilsDB = new UtilsDB();

return _UtilsDB;
}
}

--bill
bill@gamespy.com
# June 21, 2003 12:40 AM

Dave Burke said:

Whoa! Beauty in simplicity. Never woulda thought of it. Thanks, Bill.
# June 21, 2003 8:27 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)