开发者

In Scala, would the following pattern match prevent excessive garbage collection?

I'm doing some heavy database processing and am getting the error message

GC overhead limit exceeded

Caused by

ResultSe开发者_如何学Got 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 by val 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 a myVal pointing to it, that won't happen until myVal goes 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜