Skip to Main Content

How do I manage static variables in C++ from JNI - memory implications

853881Apr 8 2011 — edited Apr 8 2011

My JNI implementation C++ file has a static variable (map) outside of any class.
I load it with an Initialize method that is called from my JNI implementation functions.
What happens to it after the function returns? Will it be cleaned up, or will it linger unattached soaking up memory?

// Map to associate the strings with the enum values
static std::map<std::string, StringValue> s_mapStringValues;

// Intialization
static void Initialize();

void Initialize()
	  s_mapStringValues["+Rl"] = evrotateleft;
	  s_mapStringValues["+Rr"] = evrotateright;

some-JNI-method( various JNI arguments ){
  Initialize();  // load the map
  // use the map
 return;  // return to Java land
Should I explicitly try to clear the map at the end of the JNI method? Will the map be preserved between JNI invocations?
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on May 6 2011
Added on Apr 8 2011