I’m doing some heavy database processing and am getting the error message
GC overhead limit exceeded
Caused by
ResultSet getString
In my code I have checks such as the following
val myVal = result.getString("COLUMN")
if (myVal == ...) {}
What I’m wondering is if I change this
result.getString("COLUMN") match {
case ...
}
Does this save a variable from having to be created and garbage collected? Or is this some internal mechanism which means that this happens anyway?
Edit: result is a JDBC ResultSet
It will not prevent object allocation. The object is allocated by
getString, not byval myVal =. What it may do is free the object sooner, since it will eligible for garbage collection as soon as no one reference it. If you have amyValpointing to it, that won’t happen untilmyValgoes out of scope.This may help you, since very short lived objects are very cheap to garbage collect. But, truth to be told, it seems unlikely.