Results 1 to 11 of 11

Thread: VB6 QUESTION: Methods for finding a memory leak.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,166

    VB6 QUESTION: Methods for finding a memory leak.

    I have a fairly large program where there appears to be a memory leak. If I run the program for a few days system memory is consumed to a point where the system runs short of memory and things start to go wrong as you would expect

    When I kill my VB6 program the memory is released. Task manager/RamMap does not show the processes memory being utilised in an abnormal manner nor is the size of its allocated memory excessive. The build up is very slow and it is only after 7-8 days that I notice RAM usage is excessive - by its absence for any other process...

    The program does a lot of GDI+, uses a lot of Win APIs and reads a lot of VB6-foreign image types (PNGs) using GDI+ and storing them in collections. It operates with quite a few timers for animation.

    It won't be an easy task and so I will dig into the code and look to see what I've been doing wrong. It'll be something to do with my failure to tidy up a structure or other, probably in GDI+ but possibly something else. I won't know until I do that digging.

    Can you please recommend any tools any methods you have successfully used that have helped you track down a memory leak? Your knowledge required and your help appreciated.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,711

    Re: VB6 QUESTION: Methods for finding a memory leak.

    Last edited by Arnoutdv; Sep 1st, 2021 at 09:19 AM.

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,664

    Re: VB6 QUESTION: Methods for finding a memory leak.

    Not knowing those tools (Arnout's post), there is pretty much the "do it yourself"-Method:
    Anytime you allocate memory, you have to free it up after you don't need it anymore,
    especially when using API's.

    In your case i'd start checking your API's (Not only GDI+), if there is any API-Call which returns "allocated memory", track down its lifetime, and make sure you free it up again.

    Otherwise: See here: https://www.vbforums.com/showthread....-and-Detection
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,320

    Re: VB6 QUESTION: Methods for finding a memory leak.

    Flat GDI+ is particularly dangerous as there is no monitoring API built-in and for bookkeeping C++ wrappers depend on language RAII which will hurt performance if reimplemented with VB6/COM classes.

  5. #5
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,504

    Re: VB6 QUESTION: Methods for finding a memory leak.

    I would replace GDI+ with WIC (Windows Imaging Component).
    also, you can use WIC and GDI32 together if you prefer that. BitBlt/AlphaBlend are still very good. GDI+ should just die.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,166

    Re: VB6 QUESTION: Methods for finding a memory leak.

    Thankyou all. I am attempting the leak detection using the guidelines as supplied.

    Quote Originally Posted by baka View Post
    I would replace GDI+ with WIC (Windows Imaging Component).
    I hear you. However I set out to create my tool specifically using technologies typically in use at the turn of the century, ie. VB6 and GDI+. Masochism appears to be my middle name. No multi-threading and GDI+ are the bane of my program but - it is working.

    I just need to do my job properly and find where I have created objects and failed to destroy them. I have a timer function that operates x times per second and performs animation. The leak is undoubtedly in there somewhere.

    At some point I will convert from GDI+ to something else, as yet undecided. However, this is where I am, so no program rewrite to newer technologies at this stage, just some bug-finding and fixing.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  7. #7
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,504

    Re: VB6 QUESTION: Methods for finding a memory leak.

    do u really need GDI+ to render? why not use GDI32? as its good enough for rendering/animation.
    GDI+ u can do any pre-work, like loading, any kind of "manipulations" and after that send them to a memoryDC.

    most of my pre-direct2d work is like that. I combine GDI+ & GDI32 but its alphablend/bitblt that Im using when I render.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,166

    Re: VB6 QUESTION: Methods for finding a memory leak.

    Nothing to do with need, it is done, the program is more or less complete. I am just debugging now.

    It is however a good recommendation and I may look into GDI for the animations later. It would be much faster.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  9. #9
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,504

    Re: VB6 QUESTION: Methods for finding a memory leak.

    another suggestion is to create a class, example, we call it "engine".
    u can do engine.initialize, engine.load, engine.render, engine.remove etc.
    that way, if u ever need to change method u only need to work on the class and not on the program itself.
    when I changed from gdi to direct2d, I just worked on the class. quite easy job and didnt take that long.

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    18,089

    Re: VB6 QUESTION: Methods for finding a memory leak.

    A few thoughts come to mind...

    First, can you speed up the failure by increasing the number of times that timer runs?
    Second, can you comment out the animation logic to prove that the failure is within that logic?
    Third, is the timer stepping on itself? Can you set bits to say it's in action and/or not in action?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,166

    Re: VB6 QUESTION: Methods for finding a memory leak.

    Good advice.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

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