nuki Posted May 28, 2009 Share Posted May 28, 2009 Hi guys, i got these 2 functions in my program and they cause a heavy memory overload... the program shows 2 world maps of a game and you can switch between them... it shows all characters you logged in to the game (silkroad online if some1 minds), where they are and what status they got with little dots on that map. to be up to date its refreshing each 2 seconds my problem is, it keeps loading memory (i watch it in the task manager) while drawing the dots. it loads the memory slowly but after some hours the RAM is almost filled. and if i change between the maps it doesnt unload the old one, it just copies another picture over it, means it looks normal but if i change 20 times between the maps i got 20 mb more reserved memory for my program -.-. i tried all kinds of _GDIPlus_ImageDispose BrushDispose etc etc and _WinAPI_DeleteObject in all combinations (at first of course i tried how it was explained in the help file) but it wont free the old memory somehow.. i'd be glad if someone could tell me where my mistake is ty for any help <3 ps: the program is working fine, i have no problems except the memory overload Code: expandcollapse popupFunc _drawPoints() $vCharCoordAll = 0 If @Compiled = 1 Then $hInstance = _WinAPI_GetModuleHandle("") If $bButtonToggle = "World Map" Then $hBitmapHandle = _WinAPI_LoadBitmap($hInstance, "worldmap") ElseIf $bButtonToggle = "Tomb Map" Then $hBitmapHandle = _WinAPI_LoadBitmap($hInstance, "tombmap") EndIf $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBitmapHandle) ElseIf @Compiled = 0 Then If $bButtonToggle = "World Map" Then $hBitmap = _GDIPlus_ImageLoadFromFile("worldmap.bmp") ElseIf $bButtonToggle = "Tomb Map" Then $hBitmap = _GDIPlus_ImageLoadFromFile("tombmap.bmp") EndIf EndIf $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap) $vWinList = WinList("[CLASS:wxWindowClassNR]") For $i2 = 1 To $vWinList[0][0] If StringInStr($vWinList[$i2][0], "SBot") And StringInStr($vWinList[$i2][0], "[") And StringInStr($vWinList[$i2][0], "]") Then $vCharname = ControlGetText($vWinList[$i2][1], "", "Static140") $vCtrlGetX = ControlGetText($vWinList[$i2][1], "", "Static135") $vCtrlGetY = ControlGetText($vWinList[$i2][1], "", "Static137") If ControlGetText($vWinList[$i2][1], "", "Static9") = "Connected" And ControlGetText($vWinList[$i2][1], "", "Static11") = "Arrived trainplace" Then $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) $hPen = _GDIPlus_PenCreate(0xFF80FF80) ElseIf ControlGetText($vWinList[$i2][1], "", "Static9") = "Connected" And ControlGetText($vWinList[$i2][1], "", "Static11") = "You died!" Then $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000) $hPen = _GDIPlus_PenCreate(0xFFFF5555) ElseIf ControlGetText($vWinList[$i2][1], "", "Static9") = "Disconnected" Then $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000) $hPen = _GDIPlus_PenCreate(0xFF000000) Else $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF) $hPen = _GDIPlus_PenCreate(0xFF1A70FF) EndIf $vLocation = ControlGetText($vWinList[$i2][1], "", "Static148") If $bButtonToggle = "World Map" Then $vCharCoordAll += 1 $hGraphicsFillEllipse = _GDIPlus_GraphicsFillEllipse($hGraphic, _getPixelX($vCtrlGetX, $vLocation) - 1, _getPixelY($vCtrlGetY, $vLocation) - 3, 5, 5, $hBrush) $hGraphicsDrawEllipse = _GDIPlus_GraphicsDrawEllipse($hGraphic, _getPixelX($vCtrlGetX, $vLocation) - 1, _getPixelY($vCtrlGetY, $vLocation) - 3, 5, 5, $hPen) $vCharCoord[$vCharCoordAll] = _getPixelX($vCtrlGetX, $vLocation) - 1 & "|" & _getPixelY($vCtrlGetY, $vLocation) - 3 & "|" & $vCharname ElseIf $bButtonToggle = "Tomb Map" Then If $vLocation = "JG Cave (lvl 1)" Or $vLocation = "JG Cave (lvl 2)" Or $vLocation = "JG Cave (lvl 3)" Or $vLocation = "JG Cave (lvl 4)" Then $vCharCoordAll += 1 $hGraphicsFillEllipse = _GDIPlus_GraphicsFillEllipse($hGraphic, _getPixelX($vCtrlGetX, $vLocation) - 1, _getPixelY($vCtrlGetY, $vLocation) - 3, 5, 5, $hBrush) $hGraphicsDrawEllipse = _GDIPlus_GraphicsDrawEllipse($hGraphic, _getPixelX($vCtrlGetX, $vLocation) - 1, _getPixelY($vCtrlGetY, $vLocation) - 3, 5, 5, $hPen) $vCharCoord[$vCharCoordAll] = _getPixelX($vCtrlGetX, $vLocation) - 1 & "|" & _getPixelY($vCtrlGetY, $vLocation) - 3 & "|" & $vCharname EndIf EndIf EndIf Next $hNewBitmapHandle = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _SetBitmapToCtrl($guiPicMap, $hNewBitmapHandle) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hNewBitmapHandle) If @Compiled = 1 Then _WinAPI_DeleteObject($hBitmapHandle) EndIf EndFunc ;==>_drawPoints Func _SetBitmapToCtrl($CtrlId, $hBitmap) Local Const $STM_SETIMAGE = 0x0172 Local Const $IMAGE_BITMAP = 0 Local Const $SS_BITMAP = 0xE Local Const $GWL_STYLE = -16 Local $hWnd = GUICtrlGetHandle($CtrlId) If $hWnd = 0 Then Return SetError(1, 0, 0) Local $oldStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) If @error Then Return SetError(2, 0, 0) _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($oldStyle, $SS_BITMAP)) If @error Then Return SetError(3, 0, 0) Local $oldBmp = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) If @error Then Return SetError(4, 0, 0) If $oldBmp <> 0 Then _WinAPI_DeleteObject($oldBmp) Return 1 EndFunc ;==>_SetBitmapToCtrl Link to comment Share on other sites More sharing options...
JackDinn Posted May 28, 2009 Share Posted May 28, 2009 (edited) if your sure you have deleted all the API and GDI objects/bitmaps etc properly i tend to give this a try Func _ReduceMemory($i_PID = -1); thx to wOuters If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc;==>_ReduceMemory just call _ReduceMemory() at the point you need or expect it to release the used mem, or if you know the PID then you can try putting that into the func call. Edited May 29, 2009 by JackDinn Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
nuki Posted May 29, 2009 Author Share Posted May 29, 2009 the problem is, im not sure if i deleted everything properly... i wanna be sure on that b4 i use an emergency solution ^^ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now