[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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.
0
bastawhiz
Asked:
bastawhiz
  • 3
  • 3
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
bastawhizAuthor Commented:
Thank you vary much! This is excellent information that I shall begin to read.

Thank you again.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now