Memory Leak?

I have a problem with my software. What has been happening is that I have noticed a slight increase in the amount of memory that my software takes up every time it changes an image's picture. For example:

Image1.BackgroundImage = ImageList1.Images.Item(0)

This code snippet would increase the amount of memory used by the size of the image in the imagelist.

One other code snippetsthat I have found to increase memory usage is:

    Public Function ResImage(ByVal Resource As String) As Bitmap

        Dim image As System.IO.Stream = GStreamResource(Resource)

        Return New Bitmap(image)

    End Function

    Public Function GStreamResource(ByVal Name As String) As IO.Stream

        Return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(Application.ProductName & "." & Name)

    End Function

and then calling:

ClickyImage.Image = ResImage("MyLittlePNG.png")

Am I thinking incorrectly that I am somehow wrongly assigning a picture to an image? Is VB just beign odd? AM I A BAD PROGRAMMER?!

Thank you.
LVL 1
bastawhizAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
In .NET, memory is not necessarily freed when you think it is. Look under "garbage collection" for all the details.

The long and short of it is that, even when memory is deallocated, .Net applications reserve it for potential future use until the application is terminated.

0
bastawhizAuthor Commented:
Ok, just for clarification, I have been using the Garbage Collection sub:

System.GC.Collect()

after every one of the subs I have put together above. Even so, I am unable to 'un-reserve' this memory. Is there a way to do that? Performance is not an issue in this software.
0
Jeff CertainCommented:
Again... even when the garbage is collected, the memory is still allocated to the application, until it is forced to release it bythe OS.

Think of a spoiled child (the application) who refuses to let any of their siblings/firends play with any of their toys (memory). Every time the child gets a chance, they grab another toy, and sit on it, until they have amassed a huge pile of toys that no one else can play with. Then, along come the parents (OS) and straighten everything out...

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

bastawhizAuthor Commented:
Thank you very much. Just to make the point distribution fair, I have a breif second question and if you can answer I'll add a little incentive ;-).

Is/are there any websites out there that specifically document the performance or speed of various subs and functions in .Net (I know they change between languages, but in general).

For example, mapping the speed of Instr() or Left() or Mid().


If you can give me a website (or more than one, for that matter), I will make sure you get at least 500 points.

0
Jeff CertainCommented:
Well... a lot of methods will execute more or less slowly depending on the object they are operating on (for instance, a datatable with 10 records is faster to search than one with 10 thousand records).

If there's a specific method you're interested in, you could wrap a timer around it and perform the method a few thousand times to benchmark it.

Alternately, one or more of these might be useful:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchMicrosoftVisualBasicNETInternals.asp
http://www.parasoft.com/jsp/smallbusiness/tool_description.jsp;jsessionid=baa6jYfqTw14Pd?product=TestNet&redname=googletest&referred=googletest
http://www.red-gate.com/code_profiling.htm
http://weblog.ikvm.net/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bastawhizAuthor Commented:
Thank you vary much! This is excellent information that I shall begin to read.

Thank you again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.