Skip to content

Commit

Permalink
Add a call to explicitly release the memory
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlu committed Apr 27, 2024
1 parent 4315d5a commit 5bcb5b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pyfqmr/Simplify.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ namespace Simplify
void update_triangles(int i0,Vertex &v,std::vector<int> &deleted,int &deleted_triangles);
void update_mesh(int iteration);
void compact_mesh();
void release_memory();
//
// Main simplification function
//
Expand Down Expand Up @@ -778,6 +779,13 @@ namespace Simplify
vertices.resize(dst);
}

void release_memory()
{
std::vector<Triangle>().swap(triangles);
std::vector<Vertex>().swap(vertices);
std::vector<Ref>().swap(refs);
}

// Error between vertex and Quadric

double vertex_error(SymetricMatrix q, double x, double y, double z)
Expand Down
4 changes: 4 additions & 0 deletions pyfqmr/Simplify.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cdef extern from "Simplify.h" namespace "Simplify" :
vector[vector[int]] getFaces()
vector[vector[double]] getVertices()
vector[vector[double]] getNormals()
void release_memory()
cdef cppclass Triangle:
int v[3]
int attr
Expand Down Expand Up @@ -91,6 +92,9 @@ cdef class Simplify :

return verts, faces, norms

def clear(self):
release_memory()

cpdef void setMesh(self, vertices_np, faces_np, face_colors=None):
"""Method to set the mesh of the simplifier object.
Expand Down

0 comments on commit 5bcb5b6

Please sign in to comment.