[node] Allow GC in spite of reference loops through the request method
The following produces a reference cycle:
var map = new mbgl.Map({
request: function () { ... }
});
map has a reference to the request function, which has a reference to
its closure, which has a reference to map.
Storing a the map options in an internal field, rather than a Persistent,
allows V8 to collect the reference cycle when none of its members have
other references.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "node_file_source.hpp"
|
||||
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
@@ -16,7 +15,8 @@
|
||||
|
||||
namespace node_mbgl {
|
||||
|
||||
class NodeMap : public Nan::ObjectWrap {
|
||||
class NodeMap : public Nan::ObjectWrap,
|
||||
public mbgl::FileSource {
|
||||
public:
|
||||
struct RenderOptions;
|
||||
class RenderWorker;
|
||||
@@ -43,8 +43,9 @@ public:
|
||||
NodeMap(v8::Local<v8::Object>);
|
||||
~NodeMap();
|
||||
|
||||
std::unique_ptr<mbgl::FileRequest> request(const mbgl::Resource&, Callback);
|
||||
|
||||
mbgl::HeadlessView view;
|
||||
NodeFileSource fs;
|
||||
std::unique_ptr<mbgl::Map> map;
|
||||
|
||||
std::exception_ptr error;
|
||||
|
||||
Reference in New Issue
Block a user