8000 fix: memory leak in TrackableObject by trop[bot] · Pull Request #27641 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: memory leak in TrackableObject #27641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions shell/browser/electron_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@ int ElectronBrowserMainParts::GetExitCode() {
return exit_code_ != nullptr ? *exit_code_ : 0;
}

void ElectronBrowserMainParts::RegisterDestructionCallback(
base::OnceClosure callback) {
// The destructors should be called in reversed order, so dependencies between
// JavaScript objects can be correctly resolved.
// For example WebContentsView => WebContents => Session.
destructors_.insert(destructors_.begin(), std::move(callback));
}

int ElectronBrowserMainParts::PreEarlyInitialization() {
field_trial_list_ = std::make_unique<base::FieldTrialList>(nullptr);
#if defined(OS_LINUX)
Expand Down Expand Up @@ -527,18 +519,6 @@ void ElectronBrowserMainParts::PostMainMessageLoopRun() {
}
}

// Make sure destruction callbacks are called before message loop is
// destroyed, otherwise some objects that need to be deleted on IO thread
// won't be freed.
// We don't use ranged for loop because iterators are getting invalided when
// the callback runs.
for (auto iter = destructors_.begin(); iter != destructors_.end();) {
base::OnceClosure callback = std::move(*iter);
if (!callback.is_null())
std::move(callback).Run();
++iter;
}

// Destroy node platform after all destructors_ are executed, as they may
// invoke Node/V8 APIs inside them.
node_env_->env()->set_trace_sync_io(false);
Expand Down
8 changes: 0 additions & 8 deletions shell/browser/electron_browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
// Gets the exit code
int GetExitCode();

// Register a callback that should be destroyed before JavaScript environment
// gets destroyed.
// Returns a closure that can be used to remove |callback| from the list.
void RegisterDestructionCallback(base::OnceClosure callback);

// Returns the connection to GeolocationControl which can be
// used to enable the location services once per client.
device::mojom::GeolocationControl* GetGeolocationControl();
Expand Down Expand Up @@ -160,9 +155,6 @@ class ElectronBrowserMainParts : public content::BrowserMainParts {
std::unique_ptr<ElectronExtensionsBrowserClient> extensions_browser_client_;
#endif

// List of callbacks should be executed before destroying JS env.
std::list<base::OnceClosure> destructors_;

mojo::Remote<device::mojom::GeolocationControl> geolocation_control_;

static ElectronBrowserMainParts* self_;
Expand Down
3 changes: 0 additions & 3 deletions shell/common/gin_helper/trackable_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ TrackableObjectBase::TrackableObjectBase() : weak_factory_(this) {
// TODO(zcbenz): Make TrackedObject work in renderer process.
DCHECK(gin_helper::Locker::IsBrowserProcess())
<< "This class only works for browser process";

electron::ElectronBrowserMainParts::Get()->RegisterDestructionCallback(
GetDestroyClosure());
}

TrackableObjectBase::~TrackableObjectBase() = default;
Expand Down
5 changes: 3 additions & 2 deletions shell/common/gin_helper/trackable_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "shell/common/key_weak_map.h"

Expand All @@ -19,7 +20,7 @@ class SupportsUserData;
namespace gin_helper {

// Users should use TrackableObject instead.
class TrackableObjectBase {
class TrackableObjectBase : public CleanedUpAtExit {
public:
TrackableObjectBase();

Expand All @@ -33,7 +34,7 @@ class TrackableObjectBase {
static int32_t GetIDFromWrappedClass(base::SupportsUserData* wrapped);

protected:
virtual ~TrackableObjectBase();
~TrackableObjectBase() override;

// Returns a closure that can destroy the native class.
base::OnceClosure GetDestroyClosure();
Expand Down
0