{"action":"created","issue":{"url":"https://api.github.com/repos/swig/swig/issues/274","repository_url":"https://api.github.com/repos/swig/swig","labels_url":"https://api.github.com/repos/swig/swig/issues/274/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/274/comments","events_url":"https://api.github.com/repos/swig/swig/issues/274/events","html_url":"https://github.com/swig/swig/issues/274","id":51665997,"number":274,"title":"Local jobject references are not released instantly on finished","user":{"login":"zbqf109","id":10152682,"avatar_url":"https://avatars.githubusercontent.com/u/10152682?v=3","gravatar_id":"","url":"https://api.github.com/users/zbqf109","html_url":"https://github.com/zbqf109","followers_url":"https://api.github.com/users/zbqf109/followers","following_url":"https://api.github.com/users/zbqf109/following{/other_user}","gists_url":"https://api.github.com/users/zbqf109/gists{/gist_id}","starred_url":"https://api.github.com/users/zbqf109/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zbqf109/subscriptions","organizations_url":"https://api.github.com/users/zbqf109/orgs","repos_url":"https://api.github.com/users/zbqf109/repos","events_url":"https://api.github.com/users/zbqf109/events{/privacy}","received_events_url":"https://api.github.com/users/zbqf109/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/swig/swig/labels/Java","name":"Java","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2014-12-11T09:46:51Z","updated_at":"2016-10-14T08:45:23Z","closed_at":null,"body":"It seems that java will only hold at most 512 local references at a single time. This is ok for most use. But if in C/C++ code there is a loop in which a JNI method is invoked, it easily runs overflow. Unfortunately I met this problem today. The auto generated code was like this below:\r\n```\r\nvoid SwigDirector_CBroipSipCallback::onLogging(char const *log) {\r\n  JNIEnvWrapper swigjnienv(this) ;\r\n  JNIEnv * jenv = swigjnienv.getJNIEnv() ;\r\n  jobject swigjobj = (jobject) NULL ;\r\n  jstring jlog = 0 ;\r\n  \r\n  swigjobj = swig_get_self(jenv);\r\n  if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {\r\n    jlog = 0; \r\n    if (log) {\r\n      jlog = jenv->NewStringUTF((const char *)log);\r\n      if (!jlog) return ;\r\n    }    \r\n    jenv->CallStaticVoidMethod(Swig::jclass_broipJNI, Swig::director_methids[2], swigjobj, jlog);\r\n    jthrowable swigerror = jenv->ExceptionOccurred();\r\n    if (swigerror) {\r\n      jenv->ExceptionClear();\r\n      throw Swig::DirectorException(jenv, swigerror);\r\n    }    \r\n    \r\n  } else {\r\n    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, \"null upcall object in CBroipSipCallback::onLogging \");\r\n  }\r\n  if (swigjobj) jenv->DeleteLocalRef(swigjobj);\r\n}\r\n```\r\nIn my C code, a function contains a loop and the onLogging method was called continuously. When I ran my Java app, I got an exception like this: JNI ERROR (app bug): local reference table overflow (max=512). So I add a line in the auto generated code:\r\n```\r\njenv->DeleteLocalRef(jlog);\r\n```\r\nsimply after the swigerror branch and my app ran properly. Sure there are many ways to avoid this problem, but I thought it is an issue of swig."},"comment":{"url":"https://api.github.com/repos/swig/swig/issues/comments/253743301","html_url":"https://github.com/swig/swig/issues/274#issuecomment-253743301","issue_url":"https://api.github.com/repos/swig/swig/issues/274","id":253743301,"user":{"login":"tobilau","id":1963821,"avatar_url":"https://avatars.githubusercontent.com/u/1963821?v=3","gravatar_id":"","url":"https://api.github.com/users/tobilau","html_url":"https://github.com/tobilau","followers_url":"https://api.github.com/users/tobilau/followers","following_url":"https://api.github.com/users/tobilau/following{/other_user}","gists_url":"https://api.github.com/users/tobilau/gists{/gist_id}","starred_url":"https://api.github.com/users/tobilau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobilau/subscriptions","organizations_url":"https://api.github.com/users/tobilau/orgs","repos_url":"https://api.github.com/users/tobilau/repos","events_url":"https://api.github.com/users/tobilau/events{/privacy}","received_events_url":"https://api.github.com/users/tobilau/received_events","type":"User","site_admin":false},"created_at":"2016-10-14T08:45:23Z","updated_at":"2016-10-14T08:45:23Z","body":"Will this issue be fixed in the near future?"}}
{"actor":{"display_login":"tobilau"}}