I'm having trouble finding out why my program leaks like the titanic.
The program works fine but if you run it for a few mins it will use up
all the memory. Every function that calls dlls through ruby dl seem to
leak.  I must be doing something stupid but I can't figure out what it
is.
I made a small program which leaks when it calls peekMessage over and
over again. You can see it take up memory in the task manager until its
all gone.
You can call getConsoleWindow over and over again and that leaks too.


require 'dl/import'
require 'dl/struct'
require 'dl/types'


module MyWin32
  extend DL::Importable
  dlload 'user32.dll' , 'kernel32.dll'

  typealias "WPARAM", "UINT"
  typealias "LPARAM", "UINT"
  typealias "HINSTANCE", "UINT"
  typealias "HMENU","UINT"


  MSG = struct [
    "HWND hwnd",
    "UINT message",
    "UINT wParam",
    "UINT lParam",
    "DWORD time",
    "ULONG pt_x",
    "ULONG pt_y"
  ]

  typealias "LPMSG","MSG*"
  extern 'HWND GetConsoleWindow()'
  extern 'BOOL PeekMessage(LPMSG,HWND,UINT,UINT,UINT)'
  extern 'UINT GetMessage(LPMSG,HWND,UINT,UINT)'

end



msgStruct2 = MyWin32::MSG.malloc
windowHandle = MyWin32.getConsoleWindow()
timer = Time.now
count = 0
while true
        #windowHandle = MyWin32.getConsoleWindow()  #This leaks too
	MyWin32.peekMessage(msgStruct2,windowHandle,0,0,0x0000)
	if(Time.now - timer) > 30 #run for 30 sec

		break

	end
	count += 1
end
puts "COUNT: #{count.to_s}"

puts "done press enter"
line = gets("\n")