2008/9/27 Garry <[EMAIL PROTECTED]>:
> Thanks - but what happens on Exit/Shutdown? Is there a method to tell
> v8 (or a v8 context) that we're exiting, so it should release
> everything?

Normally there is no reason to do any cleanup on process termination,
since all file handles and network connections etc. are automatically
terminated by the file system. All the resources, including memory, of
a process are forcibly released when a process exits, so it's unlikely
that the GC even runs at that time.

If you need to explicitly release a custom resource, you should look
at defining an atexit callback in C++.

>
> Although my weak objects get collected after while in normal usage,
> the weak reference callback doesn't get called on the objects that
> still exist when exiting.
>
> The only thing I've found is calling Dispose on the (single) context -
> and that doesn't seem to do anything.
>
> garry
>
> On Sep 27, 5:15 pm, deanm <[EMAIL PROTECTED]> wrote:
>> A weak callback is called when an object than has a persistent handle
>> is found unreferenced during garbage collection.  This is similar to
>> "finalizers" in other languages, for example Ruby.  This is why you
>> don't see the function getting called "right away", it will be called
>> when there is a GC.  If you want to trigger a GC, you could look at
>> the GC extension.  For example, when running with --expose-gc, a gc()
>> method will be installed on the global object.  I believe even this is
>> not guaranteed to collect your objects, it depends how deep of a
>> garbage collection is performed, and what space your objects are
>> living in.
>>
>> On Sep 27, 2:15 pm, Garry <[EMAIL PROTECTED]> wrote:
>>
>> > Hi - I realised that in my code the weak function does get called, but
>> > it isn't kicking in until about 4000 objects are created.
>>
>> > I put a counter in my create/destroy functions, and after 10,000
>> > objects are created and I shut down, 3600 still exist undestroyed.
>>
>> > Is there a certain function I should be calling to tell V8 that I've
>> > finished and it's time to collect all those remaining objects?
>>
>> > At the moment the only `shutdown' I'm doing is context.Dispose(); - is
>> > that all that needs to be done?
>>
>> > As for your question, I did notice that in the Chrome code in their
>> > weak gc function they called object.ClearWeak(); - but that might just
>> > be to remove any hanging pointers.
>>
>> > I'd really love to see an official example of this kind of stuff. All
>> > the examples I have found of weak references are using a global or
>> > member var rather than a new/delete system.
>>
>> > garry
>>
>> > On Sep 27, 9:59 am, bell <[EMAIL PROTECTED]> wrote:
>>
>> > > In my tests, it works, with the MakeWeak-callback. The callback ist
>> > > called the first time, when there are about 400 unused Persistent
>> > > Objects allocated
>>
>> > > i use following js code to test, where the fuction myobj returns a
>> > > Persistent Object
>>
>> > > for (var c=0;c<200000;c++) {
>> > >    var x=myobj()
>>
>> > > }
>>
>> > > unfortuanatly, when i have allocated and deallocated about 160000
>> > > objects, my program crashes. it looks like the GarbageCollector isn't
>> > > freeing the Persistent Object after calling theMakeWeak-callback.
>>
>> > > in my callback i only delete my c++ object, do i have to do something
>> > > with the Persistent<Object> ?
>>
>> > > markus
>>
>> > > On 26 Sep., 22:55, Garry <[EMAIL PROTECTED]> wrote:
>>
>> > > > Hey - did you solve this problem? I'm facing the same thing right
>> > > > now..
>>
>> > > > I want to make an object that I push into Javascript, then when JS
>> > > >garbagecollects it I get a callback so I can delete the c++ side
>> > > > pointer. Is this the wrong approach?
>>
>> > > > garry
>>
>> > > > On Sep 22, 9:57 am, [EMAIL PROTECTED] wrote:
>>
>> > > > > Thank you for the example.
>> > > > > I also use:
>> > > > >            ........
>> > > > >         Persistent<Object> self = 
>> > > > > Persistent<Object>::New(args.Holder());
>> > > > >         self.MakeWeak(0, Point_Destroy);
>>
>> > > > >         self->SetInternalField(0, External::New(p));
>> > > > >         return self;}
>>
>> > > > > void Point_Destroy(Persistent<Object> self, void* parameter)
>> > > > > {
>> > > > >         Local<External> external = 
>> > > > > Local<External>::Cast(self->GetInternalField(0));
>>
>> > > > >        deletestatic_cast<Point*>(external->Value());
>>
>> > > > > }
>>
>> > > > > but the "Point_Destroy" Function is never called. So when should it 
>> > > > > be
>> > > > > called in your example?
>>
>> > > > > Thanks
>> > > > > bg- Zitierten Text ausblenden -
>>
>> > > > - Zitierten Text anzeigen -
> >
>

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to