Are there opposites of app.doScript() or $.evalFile() to delete from memory?

Engaged ,
Jun 29, 2018 Jun 29, 2018

Copy link to clipboard

Copied

Hey guys, I'm making a panel that uses the CodeMirror library to act like a pocket IDE / native text editor for scripting, that can 'load' (by writing to a .jsx file which is immediately $.evalFile'd) snippets of jsx and transfer any error messages between:

PW_A1.gif

PW_A2.gif

This works really well and I like the idea of these independent "notesnippets" to work with in a sandbox, but I'm not sure how I would edit or delete them after using $.evalFile on these snippets. Since I write to a file then $.evalFile(), I don't know how to do the opposite -- say I want to edit the snippet's contents then reload them so their values are updated, I notice that the original values still remain even if I:

     1) Rewrite the contents of the file then $.evalFile() it again

     2) Delete the file, then write and eval or doScript() it.

     3) Try uneval() (which I'm sure isn't for this purpose, but I can't find any explanations of it's use and hardly any examples online, of which I don't understand the context of)

So I imagine that using $.evalFile() is returning a new instance while the original instance is still being evaluated without regard to the referenced file's current contents? Can I delete a $.evalFile()'s results from memory in order to clear it without refreshing the extension, which would allow me to subsequently write new values in with a new $.evalFile() using variables or functions with the same name? Overwrite, modify or delete them?

TOPICS
Scripting

Views

514

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 02, 2018 Jul 02, 2018

Copy link to clipboard

Copied

Still stumped by this, and I'm pretty new to coding so I may be overlooking something really obvious but I'd appreciate any input.

I found that you can remove javascript files from a document by identifying it with getElementsByTagName("script)" and deleting it, and I wish I could incorporate something similar here but JSX files don't show up in the Sources panel in CEF debugging, which makes me pretty curious where I could find them. Is there any way to see what JSX files are actively running (/have been evaluated) during this given session and programmatically access that information through an extension?

I realize that I could store all the information; like how many snippets and what their contents are; in persistent cookies or through I/O via adobe.cep.fs.readFile then simply reload the panel each time I remove or make a modification to any given snippet to effectively rebuild the UI and eval stack to solve this problem, but that seems like a hacky solution and I'd like that to be a last resort.

Is there any way (through JS, JSX or any other means) to remove or uneval a script after having used $.evalFile to initialize it?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 04, 2018 Jul 04, 2018

Copy link to clipboard

Copied

It really depends on how messy the loaded file looks like but you could set loaded vars to null and call garbage collector with $.gc();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 04, 2018 Jul 04, 2018

Copy link to clipboard

Copied

Hi Loic, that sounds really promising. I looked in the ESTK OMV's description and read the MDN doc about garbage collection, but I only see discussions mentioning it's use without solid examples for Adobe scripting.

The loaded files (if we're not talking the main extension and only snippets) are meant to be very small, just a few lines or so, should only contain variables or functions without allowing anything else, and ideally shouldn't be messy at all. I only want to clear/delete the snippet if pressing the garbage can on the right side of the panel in the demo in the original post so it's no longer available during this session.

Can you point out what's wrong here?

// example full snippet:

var example = app.documents[0].name;

//

alert(example)

example = null;

$.gc()

alert(example)

It returns null, but I'm guessing it should return undefined if it actually cleared. I already have a function that splices variable and function names from the snippet (for the preview of the snippet's title) and could set those to null through another function then eval them over again. I feel like if I had to automate setting the loaded variables to null before running garbage collection regardless, then I might as well just leave it at setting them to null unless there'd be any concern with memory or bad practice doing it that way?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

LATEST

I'm sorry for the necro here - but calling $.gc() in the same function as the variable you want to null would do nothing since it's still in scope - and, according to how the script is reading it, very much in play - even though its value is now null. That's why it returns null and not undefined. Maybe execute the block in an inner func and null it there - then call $.gc() afterward.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines