Skip to content

Commit

Permalink
Correct the usage of finalize in TracingControllerAndroid class.
Browse files Browse the repository at this point in the history
TracingControllerAndroid should destroy its native instance when it
is done instead of relying on finalize() to destroy it, as vm does
not guaranteed finalize() will be called.
(source: http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#finalize%28%29)

Implement destroy() to immediately destroy native instance.

BUG=None.

Review URL: https://codereview.chromium.org/386983002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283177 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
wajahat.s@samsung.com committed Jul 15, 2014
1 parent 9c70c93 commit 00e83dd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ Mirela Budaes <mbudaes@adobe.com>
Mitchell Rosen <mitchellwrosen@chromium.org>
Mohamed I. Hammad <ibraaaa@gmail.com>
Mohamed Mansour <m0.interactive@gmail.com>
Mohammed Wajahat Ali Siddiqui <wajahat.s@samsung.com>
Mrunal Kapade <mrunal.kapade@intel.com>
Myles C. Maxfield <mymax@amazon.com>
Naiem Shaik <naiem.shaik@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public boolean queueIdle() {
public void onTerminate() {
try {
getTracingController().unregisterReceiver(this);
getTracingController().destroy();
} catch (SecurityException e) {
// Happens if the process is isolated. Ignore.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ public void getCategoryGroups() {

@Override
protected void finalize() {
// Ensure that destroy() was called.
assert mNativeTracingControllerAndroid == 0;
}

/**
* Clean up the C++ side of this class.
* After the call, this class instance shouldn't be used.
*/
public void destroy() {
if (mNativeTracingControllerAndroid != 0) {
nativeDestroy(mNativeTracingControllerAndroid);
mNativeTracingControllerAndroid = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ public void run() {
// It says it stopped, so it should have written the output file.
assertTrue(file.exists());
assertTrue(file.delete());
tracingController.destroy();
}
}

0 comments on commit 00e83dd

Please sign in to comment.