mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Reduce persistent CEF V8 memory usage by tracking objects on a per-context basis and not persisting objects when the underlying V8 handle is unused (issue #484).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@884 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "include/cef_v8.h"
|
||||
#include "libcef/common/tracker.h"
|
||||
#include "libcef/renderer/thread_util.h"
|
||||
|
||||
#include "v8/include/v8.h"
|
||||
@ -30,10 +31,25 @@ class CefV8ContextState : public base::RefCounted<CefV8ContextState> {
|
||||
virtual ~CefV8ContextState() {}
|
||||
|
||||
bool IsValid() { return valid_; }
|
||||
void Detach() { valid_ = false; }
|
||||
void Detach() {
|
||||
DCHECK(valid_);
|
||||
valid_ = false;
|
||||
track_manager_.DeleteAll();
|
||||
}
|
||||
|
||||
void AddTrackObject(CefTrackNode* object) {
|
||||
DCHECK(valid_);
|
||||
track_manager_.Add(object);
|
||||
}
|
||||
|
||||
void DeleteTrackObject(CefTrackNode* object) {
|
||||
DCHECK(valid_);
|
||||
track_manager_.Delete(object);
|
||||
}
|
||||
|
||||
private:
|
||||
bool valid_;
|
||||
CefTrackManager track_manager_;
|
||||
};
|
||||
|
||||
// Base class for V8 Handle types.
|
||||
@ -54,7 +70,7 @@ class CefV8HandleBase :
|
||||
// context will be used.
|
||||
explicit CefV8HandleBase(v8::Handle<v8::Context> context);
|
||||
|
||||
private:
|
||||
protected:
|
||||
scoped_refptr<CefV8ContextState> context_state_;
|
||||
};
|
||||
|
||||
@ -184,7 +200,9 @@ class CefV8ValueImpl : public CefV8Value {
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments) OVERRIDE;
|
||||
|
||||
v8::Handle<v8::Value> GetHandle() { return handle_->GetHandle(); }
|
||||
v8::Handle<v8::Value> GetHandle(bool should_persist) {
|
||||
return handle_->GetHandle(should_persist);
|
||||
}
|
||||
|
||||
protected:
|
||||
// Test for and record any exception.
|
||||
@ -198,12 +216,15 @@ class CefV8ValueImpl : public CefV8Value {
|
||||
Handle(v8::Handle<v8::Context> context, handleType v, CefTrackNode* tracker)
|
||||
: CefV8HandleBase(context),
|
||||
handle_(persistentType::New(v)),
|
||||
tracker_(tracker) {
|
||||
tracker_(tracker),
|
||||
tracker_should_persist_(false) {
|
||||
}
|
||||
virtual ~Handle();
|
||||
|
||||
handleType GetHandle() {
|
||||
handleType GetHandle(bool should_persist) {
|
||||
DCHECK(IsValid());
|
||||
if (should_persist && tracker_ && !tracker_should_persist_)
|
||||
tracker_should_persist_ = true;
|
||||
return handle_;
|
||||
}
|
||||
|
||||
@ -214,6 +235,10 @@ class CefV8ValueImpl : public CefV8Value {
|
||||
// internal data or function handler objects that are reference counted.
|
||||
CefTrackNode* tracker_;
|
||||
|
||||
// True if the |tracker_| object needs to persist due to an Object or
|
||||
// Function type being passed into V8.
|
||||
bool tracker_should_persist_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Handle);
|
||||
};
|
||||
scoped_refptr<Handle> handle_;
|
||||
|
Reference in New Issue
Block a user