IsNothing

  • Thread starter Thread starter Brian Linden
  • Start date Start date
B

Brian Linden

I cache a ton of stuff, and my ASP.NET application works great....but......

When I am stress testing it I'll get the "Object reference not set to an
instance of an object"
every once in a while...

It tends to happen when the cache is expired.....
I do a lot testing to make sure that it actually returns the object out of
cache...
I insure that it is a valid object, then when I try to use it I get that
error.

My question is this: When get something out of cache:

Return
CType(System.Web.HttpContext.Current.Cache.Get(CAFactory.Conts.CACHE_MANAGER
), CAManager)

I believe this returns a reference to the object, so in the instant that I
return the correct reference and I am about to use it, it expires....so the
object doesn't exist anymore?

Am I thinking about this correctly? Should I test for this all the time?

If not isnothing(object) then object.Function()

What kind of performance impact would this have?
Is the "IsNothing()" function expensive?

- Brian
 
Brian,

The isNothing is only testing if there is a value in the reference from an
object.

I personaly find nicer

If Not object Is Nothing then

I hope this helps?

Cor
 
Brian Linden said:
What kind of performance impact would this have?
Is the "IsNothing()" function expensive?

I assume it's more expensive than using 'If ... Is Nothing Then...'. Don't
worry about the performance, checking if a reference is a 'Nothing'
reference is very fast.
 
Back
Top