I reported this to Jiri. Here is my report:
I got a short answer to this mail, but my successive e-mails have not any response:I have scripts with dialog boxes with many controls and almost all of this controls have registered event handlers. I just recently noticed memory leaks when I open/close dialog boxes several times. Well, I think that solution is relatively simple: I just need to unregister all those event handlers when I closing dialog boxes (this should be mentioned in the wiki).
However, there is one thing which could not be resolved in such way: Option sheet. I have registered event handlers for some controls from the option sheet in the InitProcedure function and I could put UnRegisterEvents method in the SaveProcedure function, but I get memory leaks when I click on the Cancel button because none of the script code is executed when user clicks on that button.
Unfortunately, with some scripts (e.g. Magic Nodes) I get memory leaks even if I execute UnRegisterEvents method after click on the OK button of the Options dialog.
Do you have some suggestion for this problem?
One more unanswered mail:I have installed TClockEx, one small program which could display free RAM, but I tried also with Task Manager and Performance Monitor. Memory is leaking and it is not returned back nevertheless how long I wait. If I open/close dialog boxes many times I could easily stay with 0 MB of memory (I have MM in some rather old machine with 512 MB of RAM). I am using FreeRAM program which could defragment RAM and return back unoccupied memory (it is working as resident in background), so I have not any problem with memory leaking, but I worry about other users which use my scripts. Well, not only my scripts, since this problem is general with all MM scripts which have RegisterEvent method.
However, the fact is next: when I put UnRegisterEvents in the end of some dialog procedure, i.e. after Form.ShowModal, memory is returned to same amount as it was before opening this dialog box not matter how many time I open and close it, but if I don't put UnRegisterEvents on the end of such procedure, the free memory is decreasing with every open/close.
Instead to write some sample script, you could try my existing scripts, most notably Magic Nodes which has most controls and event handlers of all and because of that memory is mostly decreasing with it (I suppose so). The last public version still don't have UnRegisterEvents on the end of any dialog procedure so you will easily notice memory leaks. Install script from http://solair.eunet.rs/~zvezdand/MagicNodes.htm, open/close the Edit / Magic Nodes Settings dialog several times and look at the free memory with Task Manager. Now, you could put Script.UnRegisterAllEvents on the end of the SettingsDialog procedure in the line 6130 and note amount of free memory again - you will see a difference.
The next test which you could try with the Magic Nodes script is with the Tools / Options dialog (click on the Magic Nodes Options just to be sure that its sheet is displayed). If you open/close this dialog several times, you will see memory leaks again. But now, putting of Script.UnRegisterAllEvents on the end of the SaveOptionSheet procedure (line 10235) has not any effect, even if you click on the OK button. As I already described, click on the Cancel button is not covered by user scripts so there is not any chance to unregister event handlers in such case.
As I said in another forum, after spending so much time trying to detect and resolve such problem, and writing report with explanation about it, I think that I deserve to get at least short information about its status. Just one sentence could satisfy me.This is now a real problem... I just discovered that Script.UnRegisterEvents don't resolve a problem with memory leaks, but only Script.UnRegisterAllEvents. I suppose that a reason for this is because I am unregistering event handlers for controls from a form which is already closed, i.e. after Form.ShowModal is executed.
You may wonder why this is a problem if I could use Script.UnRegisterAllEvents. Well, with the Magic Nodes Settings dialog I could create new nodes and when I do this I execute next lines:
Script.RegisterEvent CustomNode, "OnFillChildren", "FillCustomNode"
Script.RegisterEvent CustomNode, "OnNodeEdited", "EditCustomNode"
Script.RegisterEvent CustomNode, "OnNodeEditText", "CustomNodeEditText"
Script.RegisterEvent CustomNode, "OnCanEditNode", "CanEditCustomNode"
Script.RegisterEvent CustomNode, "OnFillTracks", "FillCustomLeaf"
So, when I apply Script.UnRegisterAllEvents I am unregistering not only event handlers for controls from a form but also all of this event handlers for newly created nodes. This means that when I close mentioned dialog, all newly created nodes are disappearing!
By the way, I just tested: memory leaks with the Magic Nodes Settings are about 2-3 MB per opening/closing of this dialog, which is not negligible if you ask me. When I put Script.UnRegisterAllEvents on the end of dialog procedure there is not any memory leaks, as I explained in my previous mail.