Results 1 to 2 of 2

Thread: [RESOLVED] Memory leak

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [RESOLVED] Memory leak

    Trying to spot a memory leak I have finally arrived at this part of code below.

    In it, 'Some operations' corresponds to plotting a geometrical shape with a specific colour and 'More operations' means plotting another shape with a different colour.

    When the CreateSolidBrush, SelectObject and DeleteObject functions are commented out the code executes fine without any leaks at all -the total number of GDI objects in the Task Manager stays constant- whereas when they are active, the GDI objects rapidly increase due to the loop. The 'More operations' part involves calling a sub where a different brush is created and destroyed with code similar to that in the calling sequence.

    Code:
            For k = 1 to N
                            
                hBrush = CreateSolidBrush(SomeColor)
                hOldBrush = SelectObject(MyBackBuffer, hBrush)
                
    ‘	    Some operations here...
    ‘            ...           
    
                SelectObject MyBackBuffer, hOldBrush
                DeleteObject hBrush
    
    ‘	    More operations here...
    ‘            ...    
      
            Next
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: [RESOLVED] Memory leak

    Please disregard this thread: the code isn't actually leaking. It's just I must have misplaced one of those API functions and this led me to think it was... But then I inadvertently transcribed to the post the correct working code.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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