CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Memory watching

  1. #1
    Join Date
    Jul 2004
    Posts
    105

    Question Memory watching

    I am having memory leaks in a program that I am working on. This not my original program. It was handed over to me because the other guy could not finish it. Now I am going through it and finding memory leaks. I can't find where the leaks are because there is a lot of code. Is there a tool in VB6 or some other tool that will allow me to watch my memory allocation and deallocation? I want to see what is not being deallocated.

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Memory watching

    Memory leaks are as I know mostly problems of objects which are not deleted correctly. So have a look if there are objects which are not set to nothing when they are not needed anymore.

    IMHO Best way to find is go with search function through your code. Look foe all 'Set' commands because a simplified rule of the above is all what is set to anything needs to be set to nothing at least when they are not needed anymore. So you have to look in which space they are valid. For example there may be class objects which are created in a Form They have to be nothing at least when you close that Form... Global objects at least when you close program and so on. Also look for collections of objects there could be a lot of objects in one collection !!
    And the empty collection itself also needs to be set to nothing.

    Doing this will be the end of memory leaks I think.

    Jonny Poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    Jul 2004
    Posts
    105

    Question Re: Memory watching

    Thanks for the information. While I look for those things does anybody else have any ideas? How about Arrays that are really large. Could those cause memory leaks?

    Some More background about the project.

    In this case the user opens the program and runs the application and then can click File->New to open a new work area which also closes the old work area. I open the application with a new work area and take note to what the memory is at. I am watching the memory in the windows task manager. As I run the application I see the memory jump up and then when I click File->New the memory jumps down some but not to where it was before. When New is clicked, the memory should come down to where it was before the application ran as if it had just opened. At least that is what I am expecting.
    Any suggestions?

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Memory watching

    Quote Originally Posted by senkyoshi
    Thanks for the information. While I look for those things does anybody else have any ideas? How about Arrays that are really large. Could those cause memory leaks?
    Arrays ? How they are created ? Huge Arrays like Dim MyArray(1000, 32000) as String or something like that ? Should be deleted automatically by VB

    Open your application start a new session in it and look at size as you did. But instead working something with your new working aerea just start a new aerea again. What happens ? This will maybe show you if its something which is connected with creation and deleting workingspace or if there are objects which are needed during running program and are not deleted properly. So you can check doing different things with your program and everytime looking after setting new workspace if it has to do with the things you are doing in that program or not. But if you get such a program to repair I know, thats a horror sometimes. Are Classes, collections used in that pgm or not ?
    If yes first look for all classes and collections if they are ok and then if they are used properly, especially deleted properly. Sometimes you will see something like that
    Code:
    Do
       Set MyObject = new SpecialObject 
       MyObjcet.AddThat
       MyObject.Property = Value
       MyObject.DoThisAndThat
       ' and here it comes
    Loop
    The next command in the loop is again:
    'Set MyObject = new SpecialObject'
    If this is done withaout adding the object to a collection or setting it to nothing then you'll get a lost object of Sort 'SpecialObject' You see ?
    I hope that helps.

    Jonny Poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured