First, let me say that I have read that documentation, and believe I
understand it.
The program is fairly complex, but I have tried to whittle down the
problem to something fairly simple. What I am trying to do is create
a C++ wrapper around the Java, so I can create pages and controls from
C++. In this particular case, I am creating a table which will have a
number of rows. Each row of the table consists of one 'GViewGroup'
object which is my class that extends ViewGroup. This object is
created as follows:
C++ Code:
jobject GApplicationImpl::CreateGroupView()
{
jobject ret = 0;
jclass cls = m_env->GetObjectClass(m_system);
jmethodID mid = m_env->GetMethodID(cls, "CreateGroupView", "()Lcom/
gabysoft/system/GViewGroup;");
if (mid != NULL)
{
jobject groupView;
if (groupView = m_env->CallObjectMethod(m_jobject, mid))
{
ret = m_env->NewGlobalRef(groupView);
m_env->DeleteLocalRef(groupView);
}
}
return(ret);
}
Java Code:
@SuppressWarnings("unused")
private GViewGroup CreateGroupView()
{
GViewGroup vg = new GViewGroup(m_activity);
return (vg);
}
Then I create GTextView objects (these are based on TextView) and
place them into the ViewGroup. These objects are created as follows:
C++ Code:
jobject GWindowImpl::CreateTextView(GRect& rect)
{
jobject ret = 0;
JNIEnv * env = m_pApplication->m_env;
jclass cls = env->GetObjectClass(m_groupView);
jmethodID mid = env->GetMethodID(cls, "CreateTextView", "(IIII)Lcom/
gabysoft/system/GTextView;");
if (mid != NULL)
{
jobject textView;
if (textView = env->CallObjectMethod(m_groupView, mid, rect.m_x,
rect.m_y, rect.m_width, rect.m_height))
{
ret = env->NewGlobalRef(textView);
env->DeleteLocalRef(textView);
}
}
return(ret);
}
Java Code:
@SuppressWarnings("unused")
private GTextView CreateTextView(int x, int y, int width, int height)
{
GTextView tv = new GTextView(this, m_context, x, y, x + width, y +
height);
this.addView(tv, x, y, width, height);
return(tv);
}
Now ordinarily I squirrel away the return from the CreateTextView into
my own data structures (note that I have added a global reference so
this should be ok, correct?) However as a test case I create a single
row of the table and then add multiple TextViews to it. The code for
this is as follows:
int cnt = 500;
GRect rect(0, 0, 100, 20);
while (cnt--)
{
jobject textView;
textView = CreateTextView(rect);
}
Now I know that this snippet produces a global memory leak, but
remember that this is only a test.
If cnt is set to 100, this code executes with no problem. If I set
cnt to 500, the program crashes on the return from the call to Java to
create the TextView with a 'SISEGV' received message.
Any help would be appreciated.
Thanks
On Sep 6, 8:01 am, Christian Linne <
christian.li...@googlemail.com>
wrote:
> You may have a look into the official jni *Programmer's Guide*:
http://java.sun.com/docs/books/jni/html/refs.html
> >
android-ndk...@googlegroups.com<
android-ndk%2Bunsu...@googlegroups.com>
> > .
> Mail (private):
linne2...@aol.com
> Mail (official):
Christian.Li...@googlemail.com,
> ICQ: 293253013