Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Deleting native and js objects/variables
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
CodeJunkie  
View profile  
 More options Jun 8 2011, 10:05 pm
From: CodeJunkie <isrne...@gmail.com>
Date: Wed, 8 Jun 2011 19:05:55 -0700 (PDT)
Local: Wed, Jun 8 2011 10:05 pm
Subject: Deleting native and js objects/variables
After figuring out how to wrap a class, with the help of another site,
I have run into a strange issue ... or undocumented feature ... which
there seems to be a lot of.

When i create an object, lets say EventManager, it calls back to C++
and uses the new keyword and wraps itself into several v8 objects.
That is fine; however, when I do something like

var evtMgr = new EventManager();

and then turn around and do

delete evtMgr;

The object still exists. Futhermore, when the program exits it leaves
a dangling pointer to the EventManager object that was created. In
addition to this, any object or variable that i create by doing
NS = {};
delete NS;

Works just fine and

var foo = 20;
delete foo;

Does not remove the variable. Any thoughts on this?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CodeJunkie  
View profile  
 More options Jun 8 2011, 10:22 pm
From: CodeJunkie <isrne...@gmail.com>
Date: Wed, 8 Jun 2011 19:22:25 -0700 (PDT)
Local: Wed, Jun 8 2011 10:22 pm
Subject: Re: Deleting native and js objects/variables
This is also with the case with the shell program in the example code.

On Jun 8, 7:05 pm, CodeJunkie <isrne...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CodeJunkie  
View profile  
 More options Jun 8 2011, 10:48 pm
From: CodeJunkie <isrne...@gmail.com>
Date: Wed, 8 Jun 2011 19:48:55 -0700 (PDT)
Local: Wed, Jun 8 2011 10:48 pm
Subject: Re: Deleting native and js objects/variables

http://code.google.com/p/v8/issues/detail?id=1196&can=8&sort=-status&...

On Jun 8, 7:22 pm, CodeJunkie <isrne...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Millikin  
View profile  
 More options Jun 9 2011, 12:58 am
From: Kevin Millikin <kmilli...@chromium.org>
Date: Thu, 9 Jun 2011 06:58:20 +0200
Local: Thurs, Jun 9 2011 12:58 am
Subject: Re: [v8-users] Deleting native and js objects/variables

On Thu, Jun 9, 2011 at 4:05 AM, CodeJunkie <isrne...@gmail.com> wrote:

> var evtMgr = new EventManager();

> and then turn around and do

> delete evtMgr;

> The object still exists.

Unlike C++, new and delete in JavaScript are not related to each other.  The
keyword new constructs a new object.  However, the keyword delete removes a
*property* from an object.  The value named by the property will not
necessarily be garbage collected---there may be other references to it.  The
value is normally not deallocated immediately in any case.

Properties introduced with 'var' are not deletable, so 'delete' correctly
does not delete the property.

> addition to this, any object or variable that i create by doing
> NS = {};
> delete NS;

> Works just fine and

> var foo = 20;
> delete foo;

> Does not remove the variable. Any thoughts on this?

Properties introduce with 'var' are not deletable.  Most other properties
are.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lasse R.H. Nielsen  
View profile  
 More options Jun 9 2011, 1:18 am
From: "Lasse R.H. Nielsen" <l...@chromium.org>
Date: Thu, 9 Jun 2011 07:18:21 +0200
Local: Thurs, Jun 9 2011 1:18 am
Subject: Re: [v8-users] Deleting native and js objects/variables
Kevin is absolutely correct. On top of that, you can actually check
whether a delete operations works - it is an expression that evaluates
to either true or false, depending on whether it manages to delete the
property. In this case it evaluates to false, which you can see by
doing, e.g.,
  print(delete foo);
in the shell.

/Lasse

--
Lasse R.H. Nielsen
l...@chromium.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CodeJunkie  
View profile  
 More options Jun 9 2011, 2:52 am
From: CodeJunkie <isrne...@gmail.com>
Date: Wed, 8 Jun 2011 23:52:06 -0700 (PDT)
Local: Thurs, Jun 9 2011 2:52 am
Subject: Re: Deleting native and js objects/variables
Hmm, yes I did test if the delete operation worked.

But I am getting some conflicting info regarding what the chrome
console can do opposed to what a base v8 build can do.

Suppose you test this:

V = {};
V.X = new Object("Test");

delete V.X; // returns true in chrome, false in the shell program
delete V;   // returns true in both;

V = {};
V.X = new Object();
delete V.X // Returns true in both
delete V; // returns true in both

// Native testing with v8
V = {};
V.X = new EventEngine();
delete V.X; // false;
delete V; // true,

Now X is lost and dangling. The C++ destructor is never called, even
at program exit. Supposedly MakeWeak will take care of this but
possibly slow down v8?

On Jun 8, 10:18 pm, "Lasse R.H. Nielsen" <l...@chromium.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CodeJunkie  
View profile  
 More options Jun 9 2011, 3:04 am
From: CodeJunkie <isrne...@gmail.com>
Date: Thu, 9 Jun 2011 00:04:25 -0700 (PDT)
Local: Thurs, Jun 9 2011 3:04 am
Subject: Re: Deleting native and js objects/variables
So I guess my real question is, how do I "delete", remove, kill, etc.
a native bound object? And yes I am aware of the GC and that it will
clean up when there are no more references to said object ... and when
it feels it needs to collect.

On Jun 8, 10:18 pm, "Lasse R.H. Nielsen" <l...@chromium.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephan Beal  
View profile  
 More options Jun 9 2011, 1:08 pm
From: Stephan Beal <sgb...@googlemail.com>
Date: Thu, 9 Jun 2011 19:08:37 +0200
Local: Thurs, Jun 9 2011 1:08 pm
Subject: Re: [v8-users] Re: Deleting native and js objects/variables

On Thu, Jun 9, 2011 at 8:52 AM, CodeJunkie <isrne...@gmail.com> wrote:
> Now X is lost and dangling. The C++ destructor is never called, even
> at program exit.

Don't get lured into that false sense of security (as i did). v8 does NOT
guaranty that GC will EVER be called, including at app exit. It does not do
a full GC at exit (supposedly as a performance boost when closing tabs in
Chrome, if my memory serves me correctly).

That means that when wrapping types which REQUIRE destructor calls for
proper semantics, you must add functions to those objects which performs
such cleanup, and call those functions from your JS code. The canonical
examples are file handles and db connections, which would have a close()
member (or similar) which cleans up the native object and sets up the object
state so that future method calls on that object will not step on a
destructed pointer.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CodeJunkie  
View profile  
 More options Jun 9 2011, 5:33 pm
From: CodeJunkie <isrne...@gmail.com>
Date: Thu, 9 Jun 2011 14:33:58 -0700 (PDT)
Local: Thurs, Jun 9 2011 5:33 pm
Subject: Re: Deleting native and js objects/variables
In other words, you have to go out of your way to delete C++ objects
which would most likely mean that you would have to have your own
memory management scheme to deal with it. So this means V8 is geared
more towards browsers than for general purpose use and should really
not be used outside the browser verse. I think that more documentation
is needed on the v8 engine to help shed light on the subject. Guess
it's back to Lua. (-_-).

On Jun 9, 10:08 am, Stephan Beal <sgb...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephan Beal  
View profile  
 More options Jun 9 2011, 6:46 pm
From: Stephan Beal <sgb...@googlemail.com>
Date: Fri, 10 Jun 2011 00:46:19 +0200
Local: Thurs, Jun 9 2011 6:46 pm
Subject: Re: [v8-users] Re: Deleting native and js objects/variables

On Thu, Jun 9, 2011 at 11:33 PM, CodeJunkie <isrne...@gmail.com> wrote:
> In other words, you have to go out of your way to delete C++ objects
> which would most likely mean that you would have to have your own
> memory management scheme to deal with it. So this means V8 is geared
> more towards browsers than for general purpose use and should really...

It is a disappointing detail, yes, but there is a way to force GC at app
shutdown:

        while( !v8::V8::IdleNotification() )
        {
        }

that will stop looping when v8 says there is nothing left to clean up.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sven Panne  
View profile  
 More options Jun 10 2011, 3:13 am
From: Sven Panne <svenpa...@chromium.org>
Date: Fri, 10 Jun 2011 09:13:04 +0200
Local: Fri, Jun 10 2011 3:13 am
Subject: Re: [v8-users] Re: Deleting native and js objects/variables

Finalizers are more complicated than most people think, and they are *not* a
replacement for destructors! Reading Boehm's classic paper "Destructors,
Finalizers, and Synchronization" (
http://www.hpl.hp.com/techreports/2002/HPL-2002-335.html) can help
understanding all issues involved before blaming implementations... ;-)

Cheers,
   S.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »