Skip to content

Commit

Permalink
Free C++ memory associated with Scala Pointers (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwalcock committed Jan 27, 2021
1 parent ef1190d commit 480d95a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions contrib/swig/src/main/scala/edu/cmu/dynet/Pointer.scala
Expand Up @@ -13,6 +13,10 @@ class FloatPointer {
def set(value: Float): Unit = dn.floatp_assign(floatp, value)

def value(): Float = dn.floatp_value(floatp)

override protected def finalize(): Unit = {
dn.delete_floatp(floatp)
}
}

class IntPointer {
Expand All @@ -24,6 +28,10 @@ class IntPointer {
def value(): Int = dn.intp_value(intp)

def increment(by: Int = 1) = set(value + by)

override protected def finalize(): Unit = {
dn.delete_intp(intp)
}
}

class UnsignedPointer {
Expand All @@ -33,4 +41,8 @@ class UnsignedPointer {
def set(value: Int): Unit = dn.uintp_assign(uintp, value)

def value(): Int = dn.uintp_value(uintp).toInt

override protected def finalize(): Unit = {
dn.delete_uintp(uintp)
}
}

0 comments on commit 480d95a

Please sign in to comment.