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/ScopedLocalRef.h | |
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/ScopedLocalRef.h')
-rw-r--r-- | include/ScopedLocalRef.h | 54 |
1 files changed, 54 insertions, 0 deletions
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 |