[texworks] SCRIPTING: TW.deleteLate()

Stefan Löffler st.loeffler at gmail.com
Sun Jun 19 10:19:27 CEST 2011


Hi,

On 2011-06-18 09:00, Paul A Norman wrote:
> Should TW.deleteLater() be callled on Dialogues once they are
> completely finished?

The short answer is: yes.

> i.e.
>
>    var convertImage =    TW.createUI("blah.blah/xxx.ui);
>
>    var ans = convertImage.exec();
>
>     TW.deleteLater(convertImage) ;
>
>
> I have had some memory issues that seem to have been solved by this.
> Is that the right way to handle this?

The longer answer is a little more complicated. Everything that
"creates" a pointer (in sloppy C++ terms) allocates memory for that.
This remains allocated until the pointer is "destroyed" again. This can
happen automatically by a number of mechanisms, but not for these
dialogs. In particular, the dialog is not tied to a particular
invocation of a script (i.e., it's not destroyed automatically when the
script ends) to allow reusing it (and possibly its data).
Ultimately, it all comes down to what is often referred to as
"ownership": the owner is responsible for destroying a pointer, whereas
everyone else has to be aware that their copy of the pointer may be
invalidated at any time.
For the sake of completeness: if you specify a parent (e.g.,
TW.createUI("file.ui", TW.target)), then the dialog will be destroyed
when TW.target is destroyed (if it still exists by then). Usually, this
won't help you much, though, as the script creating the dialog could be
called hundreds of times before TW.target is destroyed.

> Anything else that TW.deleteLater()  should be used for at all please?

Basically, anything that creates a pointer for the script and returns it
is a good candidate for deleteLater(). So from quickly browsing through
TWScriptAPI.h/.cpp, progressDialog will need a deleteLater() as well.

HTH
Stefan


More information about the texworks mailing list