I have a question that I think I know the answer to, but before I commit
myself I want to validate that I am correct.
The question: (the important part)
==============
I have set up an implementation of an embedded debugger. I want to know if I
can be notified any time a new attribute is added to my instance scope
(specifically, that's the scope that the script is running under, and any
child ScriptableObject(s) under it).
Why I need this: (extra detail)
=================
I need to calculate the relative memory a script consumes (I don't need
absolute memory used, just a number I can compute relative to what other
scripts are running so that I can keep untrusted scripts from
over-allocating memory).
My current approach: (fyi)
====================
Is to recursively iterate over all ScriptableObject(s) from the instance
scope down using Scriptable.getIds() after every X lines of code execute.
It's pretty easy to computer a numeric value for each possible attribute
(null, Undefined, Number, String, Object+it's recursive attributes). However
I run into a problem with multiple references (e.g. var y = new
Array("Green", "Blue"); var z = y[0]; both reference the same string
object). So if I use my approach I count the string "Green" twice which
isn't a fair representation of the actual memory utilization.
My best solution to this, if I can't just get notified of a new attribute
creation, is to add a flag to ScriptableObject, then my recursive algorithm
above can flip it on each memCount operation to ensure it doesn't double
count objects with multiple references. However this requires me to change
the Rhino base classes which is inelegant. Not to mention the fact that a
full scan each X steps is inefficient. Thus my search for a better solution.
Thanks!
David
p.s. Norris: thanks for the previous response, I just didn't understand the
delete operator well enough, it now makes sense how to deal with the case.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino