Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

New Post: Memory consumption

$
0
0
Wow, reply on sundays. Thank you.
I don't assume a bug in clearscript, this is why I posted in the discussions forum not on the issue list.

I uploaded the project to bitbucket: https://bitbucket.org/jrosskopf/dbchangetrackingeventproducer.

The entry point to the script-processing is done in V8DbChangeToCypherProjector::ToCypherQueries(). I tried out there not to supply the "unitOfWork" to an empty version of "Application.js" script.

If you would rather like a stripped down version, I could try to do that. But sometimes IMHO the bigger picture is helpful.

Regards
Joachim

New Post: Memory consumption

$
0
0
Hi Joachim,

Thanks for posting your project. It looks like you're employing quite a sophisticated mix of technologies - exactly the sort of ClearScript usage we're hoping to enable.

We're taking a look, but in the meantime it would definitely be very helpful to have a small code sample that reproduces your symptoms. A test program with minimal external dependencies would be perfect.

Cheers!

New Post: Using ClearScript. WebApplication problem

$
0
0
I encountered the error caused by LoadAllAssembliesFromAppDomainBinDirectory trying to load every single assembly in the bin directory (as its name suggests!).

But I found that I could stop ASP.NET from loading specific assemblies, like this:
<system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <remove assembly="ClearScriptV8-32" />
        <remove assembly="ClearScriptV8-64" />
With that change to my Web.config, I find no other changes are needed. I didn't have to reference ClearScript directly from my web app project, or add the ClearScript auxiliary V8 DLLs to the root of the project as non-copying resources.

New Post: Using ClearScript. WebApplication problem

$
0
0
Hi danielearwicker,

Thanks you very much for posting your findings!

Cheers!

New Post: Very simple app - apparent memory leak

$
0
0
Hi - I'm sure I'm doing something wrong here, as there is no way this kind of issue could slip through your tests...

I added clearscript to a complex application I develop, and had major memory problems, so have stripped it down to the simplest reproduction of the issue that I can.

It seems like some internal clearscript instances of c# runtime objects aren't being garbage collected.

Running .NET Memory Profiler by SciTech produces the following chart

Image

The chart is produced by the following code (just a timer on a form with a 1000ms interval)
     private void timer1_Tick(object sender, EventArgs e)
    {
        JScriptEngine aEngine = null;
        try
        {
            aEngine = new Microsoft.ClearScript.Windows.JScriptEngine();
            aEngine.AddHostType("Console", typeof(Console));
            aEngine.Execute(@"Console.WriteLine(""Hello"");");
        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            aEngine.Dispose();
        }
    }
You can see when garbage collection happens, and half of the instances and half of the memory isn't cleaned up. The sawtooth pattern you see there will just keep going and going and going until the PC shuts down.

I am using the JScript engine as you can see, I cannot install V8 in the environment where the application will be deployed.

please help
thanks,
Simon

New Post: typeof operator on a .NET method returns "object" - is that correct?

$
0
0
Hi,

Using ClearScriptConsole, I find:
-> host.Where
[HostMethod:Where]
-> typeof host.Where
object
That is, a method on a host object is not reported to be a "function", even though it can be called with (). Contrast this with the situation in IE or Chrome's debug consoles:
typeof console.log
"function"
Why is this important? Generic JavaScript utility functions often need the ability to sniff for "callable" values, which they do using typeof === "function".

I encountered this when trying to use JSON.stringify on a tree of objects, e.g. a JS array of host objects. I need to control how the host object is serialised, so (in accordance with how JSON.stringify works) I implemented toJSON as a method on my host class. But JSON.stringify uses typeof to check whether toJSON is a function. It gets the answer "object", so it does not call it.

New Post: Very simple app - apparent memory leak

$
0
0
Hi Simon,

Yes, we also discovered this (very recently) and posted a potential fix. The issue affects applications that repeatedly create script engine instances (of any type) and use them to run scripts that invoke host methods.

If possible, please try the fix and let us know if it works for you.

Thanks!

New Post: typeof operator on a .NET method returns "object" - is that correct?

$
0
0
Hi danielearwicker,

What you're seeing is correct. Host objects can't masquerade as JavaScript functions.

For JSON there are several possibilities. For example, you could add a custom toJSON() method to your JavaScript array. You could also pass a replacer function to JSON.stringify().

In theory it's also possible for a host object to expose a property whose value is a script function, although that doesn't seem to work for toJSON() in V8; apparently it checks more than just the typeof string.

Finally, you can use a host object as the prototype of a wrapper to which you can add whatever you need.

Good luck!

New Post: How to loop through IEnumerable in javascript

$
0
0
Hello ClearScript,

I have a host object ProductManager and it provides a function to search products:
public IEnumerable<Product> Search(string condition);
How can I loop through the IEnumerable result in JavaScript likes following:
In C#:
ProductManager manager = new ProductManager();
engine.AddHostObject("productManager", manager );
engine.AddHostType("console", typeof(Console));
In JavaScript:
var results = productManager.Search("price > 100");
for (XXXXXXXX)   <- how to write the for statement here?
{
     ......
}
Should I use the ToArray() first just likes the following?
var results = productManager.Search("price > 100").ToArray();
for (var i = 0; i < results.Length; i++)
{
    console.WriteLine(results[i].Name);
}

New Post: Microsoft languages

$
0
0
Hi, can you implement Microsoft languages like js.net c# vb.net?

New Post: Memory consumption

$
0
0
Hey,

I tried to reproduce with a simple combination of DataFlow and Clearscript. But I was not able to reproduce the memory leaking behavoir.
So I will try to lock down the problem any further.

On wednesday someone also reported a memory leak and you proposed a fix. Could that be somehow connected? Will you provide a nuget update with this patch included anytime soon, or is it better roll our own build?

Regards

Joachim

New Post: Using ClearScript. WebApplication problem

$
0
0
Another observation: SQL Compact for .NET places only the architecture-neutral API assembly in the normal load path (e.g. webapp\bin). It has x86 and x64 subdirectories (e.g. webapp\bin\x86) for everything else. Presumably this means the fixed-bitness DLLs are not inadvertently loaded by ASP.NET.

New Post: How to loop through IEnumerable in javascript

$
0
0
Greetings!

You should be able to use the IEnumerable interface directly. For example:
var results = productManager.Search('price > 100');
var enumerator = results.GetEnumerator();
while (enumerator.MoveNext()) {
    console.WriteLine(enumerator.Current.Name);
}
Thanks for your question, and good luck!

New Post: Microsoft languages

$
0
0
Hi furesoft,

Please clarify your question. ClearScript aims to integrate existing script language interpreters with .NET. Implementing script language interpreters is not its goal.

Cheers!

New Post: Memory consumption

$
0
0
Hi Joachim,

On wednesday someone also reported a memory leak and you proposed a fix. Could that be somehow connected?

To reproduce that memory leak the application has to (a) repeatedly instantiate and dispose script engines, and (b) invoke host methods from script code. You mentioned above that your issue can be reproduced without exposing host objects at all, so it appears to be unrelated.

Will you provide a nuget update with this patch included anytime soon, or is it better roll our own build?

We don't provide ClearScript binaries; the NuGet packages were all developed externally. However, we've tried to make building ClearScript as easy as possible. We recommend doing so, if only for the ability to integrate updates more quickly.

Good luck!

New Post: Enriching an object in script = object disposed exception?

$
0
0
Hi,

Probably doing something stupid, but in my host app I have an object, which I pass into the script engine. The script then adds some new properties to it (it's a dynamic), then the engine is disposed and my host object contains these new properties.

However, in my script, if I add a new property to the object like this;
theObject.someNewProperty = {
     innerProperty1 = 10,
     innerProperty2 = "Hello world"
};
If I then access theObject.someNewProperty within my host, after the engine has disposed, I get an ObjectDisposedException.

Any thoughts / assistance appreciated.

Cheers
Tony

New Post: Enriching an object in script = object disposed exception?

$
0
0
Hi Tony,

Your code above creates a property (named "someNewProperty") whose value is a script object.

Fundamentally, a script object is not a standalone object; it can be considered a sort of reference into a script engine's in-memory state. Accessing the properties of a script object requires the services of the script engine that created it.

In your scenario, consider using a host object instead. For example:
// C#
engine.AddHostType("ExpandoObject", typeof(ExpandoObject));
and then:
// JavaScript
theObject.someNewProperty = new ExpandoObject();
theObject.someNewProperty.innerProperty1 = 10;
theObject.someNewProperty.innerProperty2 = 'Hello world';
Good luck!

Source code checked in, #1d9a59279c1a4ebedbab3c4eac90dfbd7c3f7d6d

$
0
0
V8ScriptEngine performance: Don't use a continuation timer when no callback is specified, don't marshal script results to be discarded in ScriptEngine.Execute().

New Post: Memory consumption

$
0
0
Hello,

just to close this thread, I was able to find a solution, which does not produce a memory leak:
Instead of using AddHostObject, I used ScriptEngines Script property to hand over data to the script. In the script I return the data back and now use Evaluate with discard: true.

Thank you for your help!

Regards

Joachim

New Post: Enriching an object in script = object disposed exception?

$
0
0
Thanks kindly - that's sorted it :)
Viewing all 2297 articles
Browse latest View live




Latest Images