Re: [libvirt] [PATCH Java] Add finalize to automatically free libvirt objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Committed. Thank you!

-- bk

On 03/20/2010 03:18 PM, Matthias Bolte wrote:
The Connect and Network classes already had finalize, add it to all
other classes that wrap libvirt objects to unify the behavior.
---
  src/main/java/org/libvirt/Device.java      |    5 +++++
  src/main/java/org/libvirt/Domain.java      |    5 +++++
  src/main/java/org/libvirt/Interface.java   |    5 +++++
  src/main/java/org/libvirt/Network.java     |    1 +
  src/main/java/org/libvirt/StoragePool.java |    5 +++++
  src/main/java/org/libvirt/StorageVol.java  |    5 +++++
  6 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/main/java/org/libvirt/Device.java b/src/main/java/org/libvirt/Device.java
index b4f9a0c..5329be5 100644
--- a/src/main/java/org/libvirt/Device.java
+++ b/src/main/java/org/libvirt/Device.java
@@ -132,6 +132,11 @@ public class Device {
          return desc;
      }

+    @Override
+    public void finalize() throws LibvirtException {
+        free();
+    }
+
      /**
       * Frees this device object. The running instance is kept alive. The data
       * structure is freed and should not be used thereafter.
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java
index e7b24ef..a80800c 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -162,6 +162,11 @@ public class Domain {
          processError();
      }

+    @Override
+    public void finalize() throws LibvirtException {
+        free();
+    }
+
      /**
       * Frees this domain object. The running instance is kept alive. The data
       * structure is freed and should not be used thereafter.
diff --git a/src/main/java/org/libvirt/Interface.java b/src/main/java/org/libvirt/Interface.java
index 44bcad5..8b97925 100644
--- a/src/main/java/org/libvirt/Interface.java
+++ b/src/main/java/org/libvirt/Interface.java
@@ -112,6 +112,11 @@ public class Interface {
          return returnValue;
      }

+    @Override
+    public void finalize() throws LibvirtException {
+        free();
+    }
+
      /**
       * Frees this interface object. The running instance is kept alive. The data
       * structure is freed and should not be used thereafter.
diff --git a/src/main/java/org/libvirt/Network.java b/src/main/java/org/libvirt/Network.java
index 3c6f313..63b1f12 100644
--- a/src/main/java/org/libvirt/Network.java
+++ b/src/main/java/org/libvirt/Network.java
@@ -64,6 +64,7 @@ public class Network {
          processError();
      }

+    @Override
      public void finalize() throws LibvirtException {
          free();
      }
diff --git a/src/main/java/org/libvirt/StoragePool.java b/src/main/java/org/libvirt/StoragePool.java
index 7de7d50..54468bd 100644
--- a/src/main/java/org/libvirt/StoragePool.java
+++ b/src/main/java/org/libvirt/StoragePool.java
@@ -115,6 +115,11 @@ public class StoragePool {
          processError();
      }

+    @Override
+    public void finalize() throws LibvirtException {
+        free();
+    }
+
      /**
       * Free a storage pool object, releasing all memory associated with it. Does
       * not change the state of the pool on the host.
diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java
index 5ae5f5c..c5a3717 100644
--- a/src/main/java/org/libvirt/StorageVol.java
+++ b/src/main/java/org/libvirt/StorageVol.java
@@ -75,6 +75,11 @@ public class StorageVol {
          processError();
      }

+    @Override
+    public void finalize() throws LibvirtException {
+        free();
+    }
+
      /**
       * Release the storage volume handle. The underlying storage volume contains
       * to exist

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]