473,320 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
Jul 24 '06 #1
3 1047
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
Jul 25 '06 #2

tshad wrote:
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
What you are doing would not create a memory leak - but, it also
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/is...I/default.aspx
http://msdn.microsoft.com/msdnmag/is...2/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]

Jul 25 '06 #3
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

"tshad" <ts**********@ftsolutions.comschreef in bericht
news:%2****************@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

Jul 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
22
by: ajay | last post by:
Why would a new of object be created without assigning it to any of variable? new A; ??? tx
5
by: August1 | last post by:
This is a short program that I have written from a text that demonstrates a class object variable created on the stack memory and another class object variable created on the heap memory. By way...
10
by: Ramprasad A Padmanabhan | last post by:
Hi All, I am a c/perl programmer trying my hand at C++. In my code below I have an array class where I am trying to add two arrays using "+" . I am not sure why I get a '0' always for the first...
3
by: roberts.noah | last post by:
Yesturday I chased down a memory leak being reported by our leak detection library. It lead me to question this line of code: str_instance = std::string(); I changed it to...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
15
by: cedgington | last post by:
I wanted to take advantage of the large set of functionality offered by the framework, so for my latest project I'm using managed C++ with .NET v2. I'm using the gcnew operator in two different...
0
by: Stodge | last post by:
Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.