Jump to content

5 lines script and GUIDelete() crashes?!


Recommended Posts

I am creating a gui and a  ScriptControl in it.

When I run GUIDelete it crashes.

What am I doing wrong?

GUICreate("")
    $sc = ObjCreate("ScriptControl");MSScriptControl.ScriptControl acts the same
    GUICtrlCreateObj($sc, 0, 0)
    GUISetState()

    GUIDelete();hang message: Autoit stopped working!

Not every control can be embedded. They must at least support an 'IDispatch' interface.

Is that the issue here?

As the Danyfirex said, ScriptControl can't be attached to a GUI.

Here is why I wanted to do it,

The ScriptControl is hogging up RAM on a long term usage so I was thinking if I attach it to a GUI and then deleting that GUI would free the memory.

I was also thinking creating a ScriptControl object from another process and then attaching to it so then I would be able to kill the process periodically and clear the memory.

But that never worked since ObjGet can't attach to another proccess obj.

To further clarify, I am using OO_JSON.au3 and it uses a ScriptControl in order to parse JSON.

Its faster than any solution out there but, simply setting a json value in a loop would build up RAM fast. So I'm searching for a solution to clear it.

 

Anyone have a suggestion?

Edited by milos83
Link to comment
Share on other sites

ScriptControl is not an Embeddable ActiveX Control like Windows Media Player.

Saludos

Link to comment
Share on other sites

9 minutes ago, Danyfirex said:

ScriptControl is not an Embeddable ActiveX Control like Windows Media Player.

Saludos

Thank you Danyfirex,

Here is why I wanted to do it,

The ScriptControl is hogging up RAM on a long term usage so I was thinking if I attach it to a GUI and then deleting that GUI would free the memory.

I was also thinking creating a ScriptControl object from another proccess and then attaching to it then I would be able to kill the proccess periodically and clear the memory.

But that never worked since ObjGet can't attach to another proccess obj.

Anyone have a suggestion?

 

To further clarify, I am using OO_JSON.au3 and it uses a ScriptControl in order to parse JSON.

Its faster than any solution out there but simply setting a json value in a loop would build up RAM fast.\So im searching for a solution to clear it.

 

 

Thanks in advance

Edited by milos83
Link to comment
Share on other sites

Hello.  You just need to free it when you're not using it. UDF design is not so good but basically you will need to do this.

 

#include <OO_JSON.au3>


ConsoleWrite(@AutoItPID & @CRLF)
Local $iMemoryUsage = _ProcessGetMemoryUsage()
ConsoleWrite("Dicionary Empty. Current Memory Usage: " & $iMemoryUsage & @CRLF)
MsgBox(0, "", "1")

Global $g_oJSON = 0
_CreateNewJsonObject() ;create

Local $jsObj
For $i=1 to 1
$jsObj=$g_oJSON.parse(FileRead("C:\Users\Raziel\Desktop\mobileread_get_books.json"))
Next

$jsObj=0 ;free Object
$iMemoryUsage = _ProcessGetMemoryUsage() ;free old Json Object and Data  and create new one
ConsoleWrite("Dicionary Empty. Current Memory Usage: " & $iMemoryUsage & @CRLF)
MsgBox(0, "", "2")

_CreateNewJsonObject()


$iMemoryUsage = _ProcessGetMemoryUsage()
ConsoleWrite("Dicionary Empty. Current Memory Usage: " & $iMemoryUsage & @CRLF)
MsgBox(0, "", "3")


;this will free old instance and free Memory
;I do not recommend to call it in a very long loop
Func _CreateNewJsonObject()
    If IsObj($g_oJSON) Then $g_oJSON=0
    $g_oJSON=_OO_JSON_Init()
EndFunc



Func _ProcessGetMemoryUsage($sProcess = @AutoItPID)
    Local Const $PROCESS_QUERY_INFORMATION = 0x400
    Local Const $PROCESS_VM_READ = 0x10
    ;get process ID
    $nPID = ProcessExists($sProcess)
    If $nPID = 0 Then Return -1
    ;get process handle, required for GetProcessMemoryInfo
    $aRet = DllCall("Kernel32.dll", "int", "OpenProcess", _
            "dword", $PROCESS_QUERY_INFORMATION + $PROCESS_VM_READ, "dword", False, "dword", $nPID)
    If @error Or ($aRet[0] = 0) Then Return -1
    $hProc = $aRet[0]
    ;create PPROCESS_MEMORY_COUNTERS to receive data, required for GetProcessMemoryInfo
    $structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword; dword; uint peakmemsize; uint memsize; uint; uint; uint; uint; uint; uint")
    $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS)
    ;call GetProcessMemoryInfo
    $aRet = DllCall("Psapi.dll", "int", "GetProcessMemoryInfo", _
            "hwnd", $hProc, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize)
    ;close process handle
    DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hProc)
    ;return memory size in kb
    Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "memsize") / 1024
EndFunc   ;==>_ProcessGetMemoryUsage

 

Saludos

 

Link to comment
Share on other sites

5 hours ago, Danyfirex said:

Hello.  You just need to free it when you're not using it. UDF design is not so good but basically you will need to do this.

 

#include <OO_JSON.au3>


ConsoleWrite(@AutoItPID & @CRLF)
Local $iMemoryUsage = _ProcessGetMemoryUsage()
ConsoleWrite("Dicionary Empty. Current Memory Usage: " & $iMemoryUsage & @CRLF)
MsgBox(0, "", "1")

Global $g_oJSON = 0
_CreateNewJsonObject() ;create

Local $jsObj
For $i=1 to 1
$jsObj=$g_oJSON.parse(FileRead("C:\Users\Raziel\Desktop\mobileread_get_books.json"))
Next

$jsObj=0 ;free Object
$iMemoryUsage = _ProcessGetMemoryUsage() ;free old Json Object and Data  and create new one
ConsoleWrite("Dicionary Empty. Current Memory Usage: " & $iMemoryUsage & @CRLF)
MsgBox(0, "", "2")

_CreateNewJsonObject()


$iMemoryUsage = _ProcessGetMemoryUsage()
ConsoleWrite("Dicionary Empty. Current Memory Usage: " & $iMemoryUsage & @CRLF)
MsgBox(0, "", "3")


;this will free old instance and free Memory
;I do not recommend to call it in a very long loop
Func _CreateNewJsonObject()
    If IsObj($g_oJSON) Then $g_oJSON=0
    $g_oJSON=_OO_JSON_Init()
EndFunc



Func _ProcessGetMemoryUsage($sProcess = @AutoItPID)
    Local Const $PROCESS_QUERY_INFORMATION = 0x400
    Local Const $PROCESS_VM_READ = 0x10
    ;get process ID
    $nPID = ProcessExists($sProcess)
    If $nPID = 0 Then Return -1
    ;get process handle, required for GetProcessMemoryInfo
    $aRet = DllCall("Kernel32.dll", "int", "OpenProcess", _
            "dword", $PROCESS_QUERY_INFORMATION + $PROCESS_VM_READ, "dword", False, "dword", $nPID)
    If @error Or ($aRet[0] = 0) Then Return -1
    $hProc = $aRet[0]
    ;create PPROCESS_MEMORY_COUNTERS to receive data, required for GetProcessMemoryInfo
    $structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword; dword; uint peakmemsize; uint memsize; uint; uint; uint; uint; uint; uint")
    $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS)
    ;call GetProcessMemoryInfo
    $aRet = DllCall("Psapi.dll", "int", "GetProcessMemoryInfo", _
            "hwnd", $hProc, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize)
    ;close process handle
    DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hProc)
    ;return memory size in kb
    Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "memsize") / 1024
EndFunc   ;==>_ProcessGetMemoryUsage

 

Saludos

 

Yeah, that is what I was doing.

I would stringify all of the data, 'null' the json and the load the data back in but its not as effective at memory clearing as expected.

Ended up just decreasing the usage of json since it has that memory leak.

Thanks @Danyfirex

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...