mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
artf4153 Adds HAL structure memory management
In the current HAL, once the port structures were created, there was no way to free the structures. The way the C++ libraries were written this wasn't a problem, since it grabbed a copy of each and stored them in an array on bootup. However java does not do this, and grabs new ports every time an object is created. This causes memory leaks if an object is ever disposed in java. The same thing looks to be happening in python, and C# does it too currently, but that would change if this gets merged. Adds java memory management fixes Adds memory management to AnalogInput and Analog Output C++ SolenoidPorts and Digital Ports are all hold static arrays with their port pointers (although solenoid overwrites them if a new solenoid on the same module is created), however analog always grabbed new pointers. I would fix the solenoid one, but I don't know what the ideal way to do it would be. Silently ignores free(null) calls by checking passed parameter is non-null. Change-Id: Id32993b57b53f896e46e55c97541d3bd90b52648
This commit is contained in:
committed by
Peter Johnson
parent
e162e4d1c0
commit
de39877efb
@@ -40,4 +40,19 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort
|
||||
return (jlong)port;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
|
||||
* Method: freePort
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_freePort
|
||||
(JNIEnv * env, jclass, jlong id)
|
||||
{
|
||||
//FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
|
||||
//FILE_LOG(logDEBUG) << "Module = " << (jint)module;
|
||||
//FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
|
||||
freePort((void*)id);
|
||||
//FILE_LOG(logDEBUG) << "Port Ptr = " << port;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user