|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Object deleted or memory leak?If I create an object (instantiate) then do it again using the same Pointer,
will I leave the old object hanging around wasting memory? Would this create a memory leak or would it be taken care of when I leave the function? ********************************************************** Sub ActiveJobEdit_Click(s as Object, e as ImageClickEventArgs) Dim newPosition as Position = new Position(oLabel.Text) .... newPosition = new Position(otherLabel.Text) session("newPosition) = newPosition End Sub ********************************************************** Thanks, Tom the great thing about VB is that (almost?) all of your memory management is
takin care of for you. the GC comes and takes care of any unused objects every so often, once u exit the sub, all local variables are GCed -- -iwdu15 tshad wrote:
Show quoteHide quote > If I create an object (instantiate) then do it again using the same Pointer, What you are doing would not create a memory leak - but, it also> will I leave the old object hanging around wasting memory? > > Would this create a memory leak or would it be taken care of when I leave > the function? > > ********************************************************** > Sub ActiveJobEdit_Click(s as Object, e as ImageClickEventArgs) > Dim newPosition as Position = new Position(oLabel.Text) > ... > newPosition = new Position(otherLabel.Text) > session("newPosition) = newPosition > End Sub > ********************************************************** > > Thanks, > > Tom wouldn't be taken care of when you leave the function... At least, probably not :) See, object life time in .NET is non-deterministic. It is controled by the garbage collector, and that generally only runs when your application is under memory pressure. Here is an article that gives a rundown of Memory management in .NET http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx The code is C# and the articles are a bit old, but it covers most of the basics. You can also read the documentation, for more details. -- Tom Shelton [MVP] Tshad,
Because there are two answers sent in the same time, I would keep it by the answer from Iwdu15, and if you have a program that is working in the area of science or something like that, than read the message from Tom. Just my thought, Cor Show quoteHide quote "tshad" <tscheider***@ftsolutions.com> schreef in bericht news:%23pBkfY3rGHA.2292@TK2MSFTNGP05.phx.gbl... > If I create an object (instantiate) then do it again using the same > Pointer, will I leave the old object hanging around wasting memory? > > Would this create a memory leak or would it be taken care of when I leave > the function? > > ********************************************************** > Sub ActiveJobEdit_Click(s as Object, e as ImageClickEventArgs) > Dim newPosition as Position = new Position(oLabel.Text) > ... > newPosition = new Position(otherLabel.Text) > session("newPosition) = newPosition > End Sub > ********************************************************** > > Thanks, > > Tom >
Windows Service Cannot Move Files
Stopping Attributes.Add from converting my JavaScript event code to HTML 2 Gig Print Spooler process Fastest way to update a Picturebox's image Dynamic Properties hiding properties or methods in inherited class Dispose of Notifier Icon Sub Main Ends so does the application Editing XML Document converting API call |
|||||||||||||||||||||||