memory leak?

13 views
Skip to first unread message

abc user

unread,
Jan 13, 2010, 5:26:12 AM1/13/10
to v8-users
The following code in serialize.cc:

int top_format_length = StrLength(top_address_format) - 2;
for (uint16_t i = 0; i < Top::k_top_address_count; ++i) {
const char* address_name = AddressNames[i];
Vector<char> name =
Vector<char>::New(top_format_length + StrLength(address_name)
+ 1);
const char* chars = name.start();
OS::SNPrintF(name, top_address_format, address_name);
Add(Top::get_address_from_id((Top::AddressId)i), TOP_ADDRESS, i,
chars);
}

allocates a new Vector each loop iteration, shouldn't it call Dispose
() method on "name" to release the allocated memory at the end of the
for loop?

abc user

unread,
Jan 13, 2010, 5:37:26 AM1/13/10
to v8-users
and when you allocate an ExternalReferenceTable object (in the same
file - serialize.cc):
static ExternalReferenceTable* instance() {
if (!instance_) instance_ = new ExternalReferenceTable();
return instance_;
}

where do you release the allocated object? I didn't find a code that
releases it.

Erik Corry

unread,
Jan 13, 2010, 5:37:40 AM1/13/10
to v8-u...@googlegroups.com


2010/1/13 abc user <junk...@gmail.com>
That would free the string data, which is still used after the loop terminates.  It is stored in the external reference table by the 'chars' argument of the 'Add(...)' call.

This routine is only called once in the lifetime of the VM and the number of external references is small and bounded so memory leaks are probably not a concern.

-- 
Erik Corry
 

Erik Corry

unread,
Jan 13, 2010, 5:39:10 AM1/13/10
to v8-u...@googlegroups.com


2010/1/13 abc user <junk...@gmail.com>

and when you allocate an ExternalReferenceTable object (in the same
file - serialize.cc):
 static ExternalReferenceTable* instance() {
   if (!instance_) instance_ = new ExternalReferenceTable();
   return instance_;
 }

where do you release the allocated object? I didn't find a code that
releases it.

It is released automatically by the operating system when the process terminates :-)
 


On Jan 13, 12:26 pm, abc user <junk....@gmail.com> wrote:
> The following code in serialize.cc:
>
>   int top_format_length = StrLength(top_address_format) - 2;
>   for (uint16_t i = 0; i < Top::k_top_address_count; ++i) {
>     const char* address_name = AddressNames[i];
>     Vector<char> name =
>         Vector<char>::New(top_format_length + StrLength(address_name)
> + 1);
>     const char* chars = name.start();
>     OS::SNPrintF(name, top_address_format, address_name);
>     Add(Top::get_address_from_id((Top::AddressId)i), TOP_ADDRESS, i,
> chars);
>   }
>
> allocates a new Vector each loop iteration, shouldn't it call Dispose
> () method on "name" to release the allocated memory at the end of the
> for loop?


abc user

unread,
Jan 13, 2010, 6:07:42 AM1/13/10
to v8-users
ok .. but I'm changing the v8 code to a thread-safe code with
intention to use it in a server application, and that would be a
problem if each v8 instance will leave some unreleased memory.

On Jan 13, 12:39 pm, Erik Corry <erik.co...@gmail.com> wrote:
> 2010/1/13 abc user <junk....@gmail.com>

Erik Corry

unread,
Jan 13, 2010, 6:25:05 AM1/13/10
to v8-u...@googlegroups.com


2010/1/13 abc user <junk...@gmail.com>

ok .. but I'm changing the v8 code to a thread-safe code with
intention to use it in a server application, and that would be a
problem if each v8 instance will leave some unreleased memory.

That's a very ambitious plan.  You should coordinate with Maxim.
Reply all
Reply to author
Forward
0 new messages