Skip to Main Content

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

853881Apr 8 2011 — edited Apr 8 2011
Hi,

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?

eg:
// 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?
Comments
Post Details
Added on Apr 8 2011
5 comments
1,689 views