From:  "Weiyang Zhou" <weiyangzhou@nowhere.com>
Date:  16 Feb 2007 02:44:33 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

Is JSString created by JS_NewStringCopyN garbage collected?

NNTP-Posting-Host:  63.237.124.70

We are running SpiderMonkey in an embedded system, but had a memory issue.

In JavaScript, I have code like this,

for (var i=0; i<100000; i++)
{
    read();
}


read() is a function implemented in C like this,

static JSBool readNative(JSContext* cx, JSObject* obj, uintN argc, jsval* 
argv, jsval* rval)
{
    char buf[1024];
    memset(buf, 'a', 1024);
    *rval = STRING_TO_JSVAL(JS_NewStringCopyN(cx, buf, 1024));
    return JS_TRUE;
}

When executing the JavaScript, we can see the heap keeps growing and 
eventually exhausts memory. Is the JSString created by JS_NewStringCopyN 
garbage collected?

Thanks
Weiyang