1
votes

I am using Cassandra prepared statements to execute my queries in a Scala application using the Datastax Cassandra Java driver.

We have conditional logic to check and see if a bound statement should execute based on some internal state of an object. Something to this effect:

def updateDatabase(x: String, y: String, z: String) = {
   val bound = statement.bind(x,y,x)     

   if(sequence_nr < current){
      session.execute(bound)
   }
}

Does this introduce a memory leak in either our Scala application or in Cassandra? My inclination is to say no but didn't want to make that assumption as I don't fully understand what the driver is doing behind the scenes with the bind call.

I appreciate the help.

1
Should be just GC'edmmatloka
That was my thought as well. I want to make sure that there isn't anything that happened on the Cassandra side when I bind the statement.nattyddubbs
That being said, it still makes more sense to call the bind inside the if. Why bind variables to a statement when you don't plan on using it?Aaron
@Aaron Great point Aaron. There's some inheritance going on in the "actual code" so I'll do some refactoring.nattyddubbs

1 Answers

3
votes

The bind() method generates a new instance of BoundStatement at each invocation, and session.execute() does not keep any reference to it, so it will be GC'ed. There is no risk of memory leaks here.