__Delete()
__Delete()
How __Delete() works? Can not understand. What is case when object delets?
Re: __Delete()
Whenever an Instance/object is deleted the function is called:
Code: Select all
Class a {
__New(name:="AHK"){
this.name:=name
}
__Delete(){
MsgBox % "Instance '" this.name "' is being deleted."
}
}
c:=new a("AutoHotkey")
c:=""
Re: __Delete()
Hm, I notice that it also start code from __Delete in this situation:
As you can see there is no c:="". That is why I asked about it.
Code: Select all
Class a {
__New(name:="AHK"){
this.name:=name
}
__Delete(){
MsgBox % "Instance '" this.name "' is being deleted."
}
}
c:=new a("AutoHotkey")
Return
Re: __Delete()
That is because AutoHotkey frees/releases all objects before it exits.
Re: __Delete()
So how to know fore sure when it will be exits?
I want to use it but can not understand in witch cases it initialises.
I want to use it but can not understand in witch cases it initialises.
Re: __Delete()
You can use it whenever you need to clear resources, save settings ...
Simple example, here the allocated memory gets freed when object is released:
Simple example, here the allocated memory gets freed when object is released:
Code: Select all
Class Mem {
__New(size:=100){
if !this.ptr:=DllCall("GlobalAlloc","UInt",0,"UInt",size){
MsgBox Error
return ""
}
}
__Delete(){
DllCall("GlobalFree","PTR",this.ptr)
}
}
c:=new Mem(1024)
MsgBox % "Memory allocated: " c.ptr
c:=""
MsgBox Memory freed
Re: __Delete()
HotKeyIt, I asked a bit different thing.
May be it is obvious for you but I'm newbie and it is not obvious for me.
So pleas tell what event should occur to initialize __Delete()?
No I can see at occurs when c:="" also it occurs when there is no c:="" as I shown in previous example.
So what are those events when __Delete() initializes apart from c:=""?
May be it is obvious for you but I'm newbie and it is not obvious for me.
So pleas tell what event should occur to initialize __Delete()?
No I can see at occurs when c:="" also it occurs when there is no c:="" as I shown in previous example.
So what are those events when __Delete() initializes apart from c:=""?
Re: __Delete()
the event is closing the script, ending th program, terminating the applicatiln, cleaning; removing every object refrence.HotKeyIt wrote:That is because AutoHotkey frees/releases all objects before it exits.
the event is WM_QUIT. exit the app
does that help a bit?
Re: __Delete()
MJs, thank you, these are what I wanted,
Pleas tell what event is here?
Pleas tell what event is here?
Code: Select all
Class a {
__New(name:="AHK"){
this.name:=name
}
__Delete(){
MsgBox % "Instance '" this.name "' is being deleted."
}
}
c:=new a("AutoHotkey")
Return
Re: __Delete()
The event is ExitApp which happens after return because script is not persistent.
Btw. terminating the application will not cause the objects to be freed, only proper ExitApp/Reload or deleting the last reference to the object.
Btw. terminating the application will not cause the objects to be freed, only proper ExitApp/Reload or deleting the last reference to the object.
Re: __Delete()
HotKeyIt, thanx!
Now I understood, it was ExitApp because in script for example no hotkeys that will not allow script to Exit?
Witch command like hotkeys make script persistent?
Now I understood, it was ExitApp because in script for example no hotkeys that will not allow script to Exit?
Witch command like hotkeys make script persistent?
Re: __Delete()
Please forgive me as I am a newbiw also but isn't #persistant make script persistant?
Re: __Delete()
#Persistent
Re: __Delete()
enthused, yep it is.
This is what is said in Help:
#Persistent
If this directive is present anywhere in the script, that script will stay running after the auto-execute section (top part of the script) completes. This is useful in cases where a script contains timers and/or custom menu items but not hotkeys, hotstrings, or any use of OnMessage() or Gui.
This is what is said in Help:
#Persistent
If this directive is present anywhere in the script, that script will stay running after the auto-execute section (top part of the script) completes. This is useful in cases where a script contains timers and/or custom menu items but not hotkeys, hotstrings, or any use of OnMessage() or Gui.
Re: __Delete()
you know it now: the event is closing the script.samardac wrote:MJs, thank you, these are what I wanted,
Pleas tell what event is here?Code: Select all
Class a { __New(name:="AHK"){ this.name:=name } __Delete(){ MsgBox % "Instance '" this.name "' is being deleted." } } c:=new a("AutoHotkey") Return
Re: __Delete()
Thanx, to all, everything is clear now!
Re: __Delete()
Just to be clear, the __Delete meta-function is called when an object is deleted ... that is, when the object loses all references. This would occur when the object variable is reassigned, the script terminates, or the object variable is cleared due to variable scope. For example, using your Class a from above, this will call the __Delete meta-function:
... but this will not (until the script terminates):
Code: Select all
#Persistent
MyFunc()
MyFunc() {
c:=new a("AutoHotkey")
}
Code: Select all
#Persistent
c:=new a("AutoHotkey")
d:=c
c:=""
Who is online
Users browsing this forum: Aqualest, Google [Bot], jdfnnl, serenite, yanjujino1 and 288 guests