diff options
author | Elliott Hughes <enh@google.com> | 2010-05-11 17:16:02 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-05-11 17:16:02 -0700 |
commit | f281667712baf8e0721ceb2cc60e7eef19c2d859 (patch) | |
tree | d5e1a32fd0b7409b719020bbb007c91673c269de /include | |
parent | 0bcf4405371581bc413563298bb9c749e4697390 (diff) | |
download | libcore-f281667712baf8e0721ceb2cc60e7eef19c2d859.zip libcore-f281667712baf8e0721ceb2cc60e7eef19c2d859.tar.gz libcore-f281667712baf8e0721ceb2cc60e7eef19c2d859.tar.bz2 |
Reduced the amount of memory used by the TimeZone display names.
Bug: 2672057
Change-Id: I2f31ff3b5fbbf5cf8e16c89ef78a5246c6c3733a
Diffstat (limited to 'include')
-rw-r--r-- | include/ScopedGlobalRef.h | 5 | ||||
-rw-r--r-- | include/ScopedLocalRef.h | 54 |
2 files changed, 57 insertions, 2 deletions
diff --git a/include/ScopedGlobalRef.h b/include/ScopedGlobalRef.h index 15a9055..1fbeabb 100644 --- a/include/ScopedGlobalRef.h +++ b/include/ScopedGlobalRef.h @@ -19,7 +19,8 @@ #include "JNIHelp.h" -// A smart pointer that provides access to a JNI global reference +// A smart pointer that creates a JNI global reference from a weak reference. +// The global reference is deleted when the smart pointer goes out of scope. class ScopedGlobalRef { public: ScopedGlobalRef(JNIEnv* env, jobject localRef) @@ -39,7 +40,7 @@ public: } } - jobject get () const { + jobject get() const { return mGlobalRef; } diff --git a/include/ScopedLocalRef.h b/include/ScopedLocalRef.h new file mode 100644 index 0000000..2cf4673 --- /dev/null +++ b/include/ScopedLocalRef.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SCOPED_LOCAL_REF_H_included +#define SCOPED_LOCAL_REF_H_included + +#include "JNIHelp.h" + +// A smart pointer that deletes a JNI local reference when it goes out of scope. +class ScopedLocalRef { +public: + ScopedLocalRef(JNIEnv* env, jobject localRef) + : mEnv(env), mLocalRef(localRef) + { + } + + ~ScopedLocalRef() { + reset(); + } + + void reset() { + if (mLocalRef != NULL) { + mEnv->DeleteLocalRef(mLocalRef); + mLocalRef = NULL; + } + } + + jobject get() const { + return mLocalRef; + } + +private: + JNIEnv* mEnv; + jobject mLocalRef; + + // Disallow copy and assignment. + ScopedLocalRef(const ScopedLocalRef&); + void operator=(const ScopedLocalRef&); +}; + +#endif // SCOPED_LOCAL_REF_H_included |