Good news is, this program calls the callback.  Bad news it crashes, but I
think it demonstrates the general idea.

I believe the problem with your program is that your global with the weak
callback goes away too early.  In my program below you can see I'm
allocating the global on the heap (and leaking the crap out of it - but you
can clean it up in the callback) and that makes the callback get called
because the global is still around.


caveat emptor


P.S. Posting a compilable program next time makes it easier for me to help
you


#include <v8.h>

#include <v8-platform.h>

#include <libplatform/libplatform.h>

#include <stdio.h>


using namespace v8;


void func_callback(const FunctionCallbackInfo<v8::Value> &data) {

  fprintf(stderr, "Here\n");

}


void weak_callback(const WeakCallbackInfo<int> &data) {

  fprintf(stderr, "weak callback\n");

}



class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {

public:

  inline virtual void* Allocate(size_t length) override {

    void* data = AllocateUninitialized(length);

    return data == NULL ? data : memset(data, 0, length);

  }

  inline virtual void* AllocateUninitialized(size_t length) override {
return malloc(length); }

  inline virtual void Free(void* data, size_t) override { free(data); }

};



int main() {

  V8::InitializeICU();

  Platform *current_platform = v8::platform::CreateDefaultPlatform();

  V8::InitializePlatform(current_platform);

  V8::Initialize();

  V8::SetFlagsFromString("--expose_gc", strlen("--expose_gc"));

  Isolate::CreateParams params;

  params.array_buffer_allocator = new ArrayBufferAllocator();

  Isolate *isolate = Isolate::New(params);

  HandleScope hs(isolate);


  Local<Context> context = Context::New(isolate);



  int iii; // bogus int


  Local<ObjectTemplate> ot = ObjectTemplate::New(isolate);

  ot->SetInternalFieldCount(1);


  for (int i = 0; ; i++) {

    HandleScope hs2(isolate);

    Local<Object> obj = ot->NewInstance(context).ToLocalChecked();

    Global<Object> * gobject = new Global<Object>(isolate, obj);

    gobject->SetWeak<int>(&iii, weak_callback, WeakCallbackType
::kParameter);

    isolate->AdjustAmountOfExternalAllocatedMemory(100000000);


    if (i%1000==0)printf("%d\r", i);

    /* context->Global()->Set(context, key, func).FromJust(); */

    /* context->Global()->Delete(context, key).FromJust(); */

  }



  return 0;

On Wed, Oct 5, 2016 at 7:56 PM, <tbl...@icloud.com> wrote:

> Actually, that didn't work. Any other ideas? Any techniques for debugging
> GC (like getting information on where an object is referenced?)
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/v8-users/Rshbi2HKYCM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to