Ask a Question related to ASP.NET General, Design and Development.
-
Carl #1
Instantiating a class in.NET
Hi,
I have a class in .Net which I instantiate in my code
behind on one of my aspx pages.
When I am finished with the instance, what is teh best
method of taking it out of memory. Should I set it to
nothing or can I dispose of it?
Thanks,
Carl.
Carl Guest
-
Pre-Instantiating Item-Renderers
Hi, I have a datagrid control which uses SWC based custom controls as its item renderers. I noticed that when I scroll up and down, the item... -
Instantiating dynamic controls?
I realize this is an old thread, but I stumbled onto this message and know the answer. instead of : myCanvas.createClassObject... -
Null pointer when instantiating CFC
Hi folks, I'm having a problem on a server, in which attempts to instantiate a CFC result in a null pointer error. I was promoting an... -
defining a class/instantiating object inside a method of anotherclass
Ok, here's what I'm trying to do. I have a class. Inside the class I have a method that reads a text file. In the text file I have a class name and... -
instantiating the ASP.DLL
Is there a way to do a CreateObject("") on the ASP.DLL? TIA Chris -
Steve C. Orr, MCSD #2
Re: Instantiating a class in.NET
Set it equal to nothing.
You shouldn't need any fancy disposal stuff unless the class is holding open
unusually valuable resources.
--
I hope this helps,
Steve C. Orr, MCSD
[url]http://Steve.Orr.net[/url]
"Carl" <carl@nospam.com> wrote in message
news:922601c35b8b$d7c639e0$a001280a@phx.gbl...> Hi,
>
> I have a class in .Net which I instantiate in my code
> behind on one of my aspx pages.
>
> When I am finished with the instance, what is teh best
> method of taking it out of memory. Should I set it to
> nothing or can I dispose of it?
>
> Thanks,
> Carl.
Steve C. Orr, MCSD Guest
-
Steve C. Orr, MCSD #3
Re: Instantiating a class in.NET
True, but it never hurts to be tidy.
In VB6 you theoretically didn't need to clean things up either, but the
reality was that sometimes the automatic cleanup didn't work quite as well
as it claimed.
It seems to behave better in .NET but I'm still not sure if I trust it 100%.
Better to be safe than sorry and clean up your own messes.
--
I hope this helps,
Steve C. Orr, MCSD
[url]http://Steve.Orr.net[/url]
"Kevin Spencer" <kevin@takempis.com> wrote in message
news:%23%23Yi3R5WDHA.652@tk2msftngp13.phx.gbl...it> It isn't necessary to set it to nothing, nor does it have any effect to do
> so (unlike COM). The object will be up for Garbage Collection as soon as> passes out of scope.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> [url]http://www.takempis.com[/url]
> Complex things are made up of
> lots of simple things.
>
> "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...> open> > Set it equal to nothing.
> > You shouldn't need any fancy disposal stuff unless the class is holding>> > unusually valuable resources.
> >
> > --
> > I hope this helps,
> > Steve C. Orr, MCSD
> > [url]http://Steve.Orr.net[/url]
> >
> >
> > "Carl" <carl@nospam.com> wrote in message
> > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...> >> > > Hi,
> > >
> > > I have a class in .Net which I instantiate in my code
> > > behind on one of my aspx pages.
> > >
> > > When I am finished with the instance, what is teh best
> > > method of taking it out of memory. Should I set it to
> > > nothing or can I dispose of it?
> > >
> > > Thanks,
> > > Carl.
> >
>
Steve C. Orr, MCSD Guest
-
John Saunders #4
Re: Instantiating a class in.NET
Steve,
Why even bother setting the reference to Nothing? This isn't COM - it won't
decrement the reference count.
--
John Saunders
Internet Engineer
[email]john.saunders@surfcontrol.com[/email]
"Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...open> Set it equal to nothing.
> You shouldn't need any fancy disposal stuff unless the class is holding> unusually valuable resources.
>
> --
> I hope this helps,
> Steve C. Orr, MCSD
> [url]http://Steve.Orr.net[/url]
>
>
> "Carl" <carl@nospam.com> wrote in message
> news:922601c35b8b$d7c639e0$a001280a@phx.gbl...>> > Hi,
> >
> > I have a class in .Net which I instantiate in my code
> > behind on one of my aspx pages.
> >
> > When I am finished with the instance, what is teh best
> > method of taking it out of memory. Should I set it to
> > nothing or can I dispose of it?
> >
> > Thanks,
> > Carl.
>
John Saunders Guest
-
Steve C. Orr, MCSD #5
Re: Instantiating a class in.NET
My mother always taught me to clean up after myself.
Old habits die hard.
:-)
--
I hope this helps,
Steve C. Orr, MCSD
[url]http://Steve.Orr.net[/url]
"John Saunders" <john.saunders@surfcontrol.com> wrote in message
news:OZ2iT35WDHA.1644@TK2MSFTNGP10.phx.gbl...won't> Steve,
>
> Why even bother setting the reference to Nothing? This isn't COM - it> decrement the reference count.
>
> --
> John Saunders
> Internet Engineer
> [email]john.saunders@surfcontrol.com[/email]
>
>
> "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...> open> > Set it equal to nothing.
> > You shouldn't need any fancy disposal stuff unless the class is holding>> > unusually valuable resources.
> >
> > --
> > I hope this helps,
> > Steve C. Orr, MCSD
> > [url]http://Steve.Orr.net[/url]
> >
> >
> > "Carl" <carl@nospam.com> wrote in message
> > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...> >> > > Hi,
> > >
> > > I have a class in .Net which I instantiate in my code
> > > behind on one of my aspx pages.
> > >
> > > When I am finished with the instance, what is teh best
> > > method of taking it out of memory. Should I set it to
> > > nothing or can I dispose of it?
> > >
> > > Thanks,
> > > Carl.
> >
>
Steve C. Orr, MCSD Guest
-
John Saunders #6
Re: Instantiating a class in.NET
Steve,
Do you clean paper plates before discarding them? Then why set a variable
to null when it's going to disappear as soon as you leave the scope? :-)
--
John Saunders
Internet Engineer
[email]john.saunders@surfcontrol.com[/email]
"Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
news:uqPhW85WDHA.2568@tk2msftngp13.phx.gbl...holding> My mother always taught me to clean up after myself.
> Old habits die hard.
> :-)
>
> --
> I hope this helps,
> Steve C. Orr, MCSD
> [url]http://Steve.Orr.net[/url]
>
>
> "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> news:OZ2iT35WDHA.1644@TK2MSFTNGP10.phx.gbl...> won't> > Steve,
> >
> > Why even bother setting the reference to Nothing? This isn't COM - it> > decrement the reference count.
> >
> > --
> > John Saunders
> > Internet Engineer
> > [email]john.saunders@surfcontrol.com[/email]
> >
> >
> > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...> > > Set it equal to nothing.
> > > You shouldn't need any fancy disposal stuff unless the class is>> > open> >> > > unusually valuable resources.
> > >
> > > --
> > > I hope this helps,
> > > Steve C. Orr, MCSD
> > > [url]http://Steve.Orr.net[/url]
> > >
> > >
> > > "Carl" <carl@nospam.com> wrote in message
> > > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...
> > > > Hi,
> > > >
> > > > I have a class in .Net which I instantiate in my code
> > > > behind on one of my aspx pages.
> > > >
> > > > When I am finished with the instance, what is teh best
> > > > method of taking it out of memory. Should I set it to
> > > > nothing or can I dispose of it?
> > > >
> > > > Thanks,
> > > > Carl.
> > >
> > >
> >
>
John Saunders Guest
-
Steve C. Orr, MCSD #7
Re: Instantiating a class in.NET
I agree that it is not a step that is necessary.
But in general it's good practice to free memory as soon as you're done with
it.
By setting the object to nothing, you're permitting the garbage collector to
pick it up immediately if it so chooses, rather than forcing it to do the
deallocation later after the entire page is done processing and it goes
completely out of scope.
Granted, this isn't likely to give you major performance increases, but if
the object is large or holds valuable resources it could theoretically help
in some circumstances.
--
I hope this helps,
Steve C. Orr, MCSD
[url]http://Steve.Orr.net[/url]
"John Saunders" <john.saunders@surfcontrol.com> wrote in message
news:eOpPSD6WDHA.1632@TK2MSFTNGP11.phx.gbl...> Steve,
>
> Do you clean paper plates before discarding them? Then why set a variable
> to null when it's going to disappear as soon as you leave the scope? :-)
>
> --
> John Saunders
> Internet Engineer
> [email]john.saunders@surfcontrol.com[/email]
>
>
> "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> news:uqPhW85WDHA.2568@tk2msftngp13.phx.gbl...> holding> > My mother always taught me to clean up after myself.
> > Old habits die hard.
> > :-)
> >
> > --
> > I hope this helps,
> > Steve C. Orr, MCSD
> > [url]http://Steve.Orr.net[/url]
> >
> >
> > "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> > news:OZ2iT35WDHA.1644@TK2MSFTNGP10.phx.gbl...> > won't> > > Steve,
> > >
> > > Why even bother setting the reference to Nothing? This isn't COM - it> > > decrement the reference count.
> > >
> > > --
> > > John Saunders
> > > Internet Engineer
> > > [email]john.saunders@surfcontrol.com[/email]
> > >
> > >
> > > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > > news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...
> > > > Set it equal to nothing.
> > > > You shouldn't need any fancy disposal stuff unless the class is>> >> > > open
> > > > unusually valuable resources.
> > > >
> > > > --
> > > > I hope this helps,
> > > > Steve C. Orr, MCSD
> > > > [url]http://Steve.Orr.net[/url]
> > > >
> > > >
> > > > "Carl" <carl@nospam.com> wrote in message
> > > > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...
> > > > > Hi,
> > > > >
> > > > > I have a class in .Net which I instantiate in my code
> > > > > behind on one of my aspx pages.
> > > > >
> > > > > When I am finished with the instance, what is teh best
> > > > > method of taking it out of memory. Should I set it to
> > > > > nothing or can I dispose of it?
> > > > >
> > > > > Thanks,
> > > > > Carl.
> > > >
> > > >
> > >
> > >
> >
>
Steve C. Orr, MCSD Guest
-
John Saunders #8
Re: Instantiating a class in.NET
If those are the same Special Circumstances I was in about a year ago (and
for 15 months) then Good Luck.
I found a damp sponge to be very effective, if you then wash the sponge in
hot water...
--
John Saunders
Internet Engineer
[email]john.saunders@surfcontrol.com[/email]
"MS News (MS LVP)" <sql_agentman@hotmail.com> wrote in message
news:OqFo$S6WDHA.1384@TK2MSFTNGP10.phx.gbl...variable> I Rinse Paper Plates Due to special circumstances
>
> J
> "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> news:eOpPSD6WDHA.1632@TK2MSFTNGP11.phx.gbl...> > Steve,
> >
> > Do you clean paper plates before discarding them? Then why set ait> > to null when it's going to disappear as soon as you leave the scope? :-)
> >
> > --
> > John Saunders
> > Internet Engineer
> > [email]john.saunders@surfcontrol.com[/email]
> >
> >
> > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > news:uqPhW85WDHA.2568@tk2msftngp13.phx.gbl...> > > My mother always taught me to clean up after myself.
> > > Old habits die hard.
> > > :-)
> > >
> > > --
> > > I hope this helps,
> > > Steve C. Orr, MCSD
> > > [url]http://Steve.Orr.net[/url]
> > >
> > >
> > > "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> > > news:OZ2iT35WDHA.1644@TK2MSFTNGP10.phx.gbl...
> > > > Steve,
> > > >
> > > > Why even bother setting the reference to Nothing? This isn't COM ->> > holding> > > won't
> > > > decrement the reference count.
> > > >
> > > > --
> > > > John Saunders
> > > > Internet Engineer
> > > > [email]john.saunders@surfcontrol.com[/email]
> > > >
> > > >
> > > > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > > > news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...
> > > > > Set it equal to nothing.
> > > > > You shouldn't need any fancy disposal stuff unless the class is> >> > > > open
> > > > > unusually valuable resources.
> > > > >
> > > > > --
> > > > > I hope this helps,
> > > > > Steve C. Orr, MCSD
> > > > > [url]http://Steve.Orr.net[/url]
> > > > >
> > > > >
> > > > > "Carl" <carl@nospam.com> wrote in message
> > > > > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...
> > > > > > Hi,
> > > > > >
> > > > > > I have a class in .Net which I instantiate in my code
> > > > > > behind on one of my aspx pages.
> > > > > >
> > > > > > When I am finished with the instance, what is teh best
> > > > > > method of taking it out of memory. Should I set it to
> > > > > > nothing or can I dispose of it?
> > > > > >
> > > > > > Thanks,
> > > > > > Carl.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
John Saunders Guest
-
John Saunders #9
Re: Instantiating a class in.NET
Steve,
I would want to see some research indicating that this is a good practice
"in general". Among other things, there may well be more overhead in
individually setting variables to null than in waiting until they go out of
scope all at once.
Also, our brains only have so much bandwidth. I'd rather spend mine on
writing code which actually _does_ something rather than on remembering to
figure out when I'm "done with" some variable just so I can give the garbage
collector a few more milliseconds to clean up a few thousand bytes on a 2Gb
server system - a few milliseconds it will probably not take advantage of.
Old folks like me need to be careful not to teach the kids our old bad
habits - even those which used to be good habits. The world has changed too
much to remain static. Machines have grown much faster and have larger
memories, and a lot of the habits I learned as a "kid" just don't matter
now. If I'd been learning today instead of 25 years ago, I would not have
been taught to set variables to null after use. I'd wonder what the big deal
was and why we couldn't just wait the few milliseconds until the end of
scope to get allow the Garbage Collector to collect this few megabytes in a
couple of seconds.
--
John Saunders (Old Dog)
Internet Engineer (the New Trick)
[email]john.saunders@surfcontrol.com[/email]
"Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
news:uBIxdQ6WDHA.2236@TK2MSFTNGP10.phx.gbl...with> I agree that it is not a step that is necessary.
> But in general it's good practice to free memory as soon as you're doneto> it.
> By setting the object to nothing, you're permitting the garbage collectorhelp> pick it up immediately if it so chooses, rather than forcing it to do the
> deallocation later after the entire page is done processing and it goes
> completely out of scope.
> Granted, this isn't likely to give you major performance increases, but if
> the object is large or holds valuable resources it could theoreticallyvariable> in some circumstances.
>
> --
> I hope this helps,
> Steve C. Orr, MCSD
> [url]http://Steve.Orr.net[/url]
>
>
> "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> news:eOpPSD6WDHA.1632@TK2MSFTNGP11.phx.gbl...> > Steve,
> >
> > Do you clean paper plates before discarding them? Then why set ait> > to null when it's going to disappear as soon as you leave the scope? :-)
> >
> > --
> > John Saunders
> > Internet Engineer
> > [email]john.saunders@surfcontrol.com[/email]
> >
> >
> > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > news:uqPhW85WDHA.2568@tk2msftngp13.phx.gbl...> > > My mother always taught me to clean up after myself.
> > > Old habits die hard.
> > > :-)
> > >
> > > --
> > > I hope this helps,
> > > Steve C. Orr, MCSD
> > > [url]http://Steve.Orr.net[/url]
> > >
> > >
> > > "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> > > news:OZ2iT35WDHA.1644@TK2MSFTNGP10.phx.gbl...
> > > > Steve,
> > > >
> > > > Why even bother setting the reference to Nothing? This isn't COM ->> > holding> > > won't
> > > > decrement the reference count.
> > > >
> > > > --
> > > > John Saunders
> > > > Internet Engineer
> > > > [email]john.saunders@surfcontrol.com[/email]
> > > >
> > > >
> > > > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > > > news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...
> > > > > Set it equal to nothing.
> > > > > You shouldn't need any fancy disposal stuff unless the class is> >> > > > open
> > > > > unusually valuable resources.
> > > > >
> > > > > --
> > > > > I hope this helps,
> > > > > Steve C. Orr, MCSD
> > > > > [url]http://Steve.Orr.net[/url]
> > > > >
> > > > >
> > > > > "Carl" <carl@nospam.com> wrote in message
> > > > > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...
> > > > > > Hi,
> > > > > >
> > > > > > I have a class in .Net which I instantiate in my code
> > > > > > behind on one of my aspx pages.
> > > > > >
> > > > > > When I am finished with the instance, what is teh best
> > > > > > method of taking it out of memory. Should I set it to
> > > > > > nothing or can I dispose of it?
> > > > > >
> > > > > > Thanks,
> > > > > > Carl.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
John Saunders Guest
-
MS News \(MS LVP\) #10
Re: Instantiating a class in.NET
Non-Sense for some servers that are hit by 10s - 100s of thousands of users
per day
What about Database Connections?
What about FileHandles?
The good old rules still apply
Machines are faster and we have more RAM but We have more demand on these
machines
Things can go out of hand with the new generation
Think about it for few years
J
"John Saunders" <john.saunders@surfcontrol.com> wrote in message
news:eYOXz18WDHA.1640@TK2MSFTNGP10.phx.gbl...of> Steve,
>
> I would want to see some research indicating that this is a good practice
> "in general". Among other things, there may well be more overhead in
> individually setting variables to null than in waiting until they go outgarbage> scope all at once.
>
> Also, our brains only have so much bandwidth. I'd rather spend mine on
> writing code which actually _does_ something rather than on remembering to
> figure out when I'm "done with" some variable just so I can give the2Gb> collector a few more milliseconds to clean up a few thousand bytes on atoo> server system - a few milliseconds it will probably not take advantage of.
>
> Old folks like me need to be careful not to teach the kids our old bad
> habits - even those which used to be good habits. The world has changeddeal> much to remain static. Machines have grown much faster and have larger
> memories, and a lot of the habits I learned as a "kid" just don't matter
> now. If I'd been learning today instead of 25 years ago, I would not have
> been taught to set variables to null after use. I'd wonder what the biga> was and why we couldn't just wait the few milliseconds until the end of
> scope to get allow the Garbage Collector to collect this few megabytes incollector> couple of seconds.
> --
> John Saunders (Old Dog)
> Internet Engineer (the New Trick)
> [email]john.saunders@surfcontrol.com[/email]
>
> "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> news:uBIxdQ6WDHA.2236@TK2MSFTNGP10.phx.gbl...> with> > I agree that it is not a step that is necessary.
> > But in general it's good practice to free memory as soon as you're done> > it.
> > By setting the object to nothing, you're permitting the garbagethe> to> > pick it up immediately if it so chooses, rather than forcing it to doif> > deallocation later after the entire page is done processing and it goes
> > completely out of scope.
> > Granted, this isn't likely to give you major performance increases, but:-)> help> > the object is large or holds valuable resources it could theoretically> variable> > in some circumstances.
> >
> > --
> > I hope this helps,
> > Steve C. Orr, MCSD
> > [url]http://Steve.Orr.net[/url]
> >
> >
> > "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> > news:eOpPSD6WDHA.1632@TK2MSFTNGP11.phx.gbl...> > > Steve,
> > >
> > > Do you clean paper plates before discarding them? Then why set a> > > to null when it's going to disappear as soon as you leave the scope?> it> > >
> > > --
> > > John Saunders
> > > Internet Engineer
> > > [email]john.saunders@surfcontrol.com[/email]
> > >
> > >
> > > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > > news:uqPhW85WDHA.2568@tk2msftngp13.phx.gbl...
> > > > My mother always taught me to clean up after myself.
> > > > Old habits die hard.
> > > > :-)
> > > >
> > > > --
> > > > I hope this helps,
> > > > Steve C. Orr, MCSD
> > > > [url]http://Steve.Orr.net[/url]
> > > >
> > > >
> > > > "John Saunders" <john.saunders@surfcontrol.com> wrote in message
> > > > news:OZ2iT35WDHA.1644@TK2MSFTNGP10.phx.gbl...
> > > > > Steve,
> > > > >
> > > > > Why even bother setting the reference to Nothing? This isn't COM ->> >> > > > won't
> > > > > decrement the reference count.
> > > > >
> > > > > --
> > > > > John Saunders
> > > > > Internet Engineer
> > > > > [email]john.saunders@surfcontrol.com[/email]
> > > > >
> > > > >
> > > > > "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> > > > > news:uWEIw24WDHA.1536@TK2MSFTNGP11.phx.gbl...
> > > > > > Set it equal to nothing.
> > > > > > You shouldn't need any fancy disposal stuff unless the class is
> > > holding
> > > > > open
> > > > > > unusually valuable resources.
> > > > > >
> > > > > > --
> > > > > > I hope this helps,
> > > > > > Steve C. Orr, MCSD
> > > > > > [url]http://Steve.Orr.net[/url]
> > > > > >
> > > > > >
> > > > > > "Carl" <carl@nospam.com> wrote in message
> > > > > > news:922601c35b8b$d7c639e0$a001280a@phx.gbl...
> > > > > > > Hi,
> > > > > > >
> > > > > > > I have a class in .Net which I instantiate in my code
> > > > > > > behind on one of my aspx pages.
> > > > > > >
> > > > > > > When I am finished with the instance, what is teh best
> > > > > > > method of taking it out of memory. Should I set it to
> > > > > > > nothing or can I dispose of it?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Carl.
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
MS News \(MS LVP\) Guest



Reply With Quote

