Memory leak when using GetPrimitiveArrayCritical()

Hi

I am using JNI to get pixel data from an invoked JVM. Unfortunately I am facing serious memory leaks when using the following code to access my byte array.


unsigned char* JVMD3DUpdateFunctions::getPixelData( unsigned char textureIndex )
{
    pixelData = (jarray)env->CallObjectMethod( rfdynhudObject, getPixelDataMethod, (jint)textureIndex );
    
    if ( pixelData == NULL )
    {
        logg( "ERROR: texture pixel data is null." );
        return ( false );
    }
    
	return ( (unsigned char*)env->GetPrimitiveArrayCritical( pixelData, &isCopy ) );
}

void JVMD3DUpdateFunctions::releasePixelData( unsigned char textureIndex, unsigned char* pointer )
{
    env->ReleasePrimitiveArrayCritical( pixelData, (void*)pointer, 0 );
    pixelData = NULL;
}

unsigned char* pixels = getPixelData( 0 );

// copy dirty rects

releasePixelData( 0, pixels );

I can guarantee, that no java or JNI call is made between these two calls. I have also verified, that the ‘pixelData’ ponter is the same in both methods.

I don’t see, what I can to differently. What am I doing wrong?

Marvin

I should probably say, that I am using a JRE 1.6 U20 32 bit on Windows 7 64 bit.

The memory leak also occurs, if I replace the GetPrimitiveArrayCritical() with GetByteArrayElements() as well as the corresponding Release.

Marvin

I think, I just got it. Adding a call to env->DeleteLocalRef( pixelData ) seems to do the trick.

Marvin