Neuro69

11-05-2009, 09:31 AM

Basically, I'm trying to do a Delaunay triangulation (based on Paul Bourke's algorithm) in MAX 2009 64-bit. I start off by reading all the vertices into an array witch is then sorted along the x-axis. This takes a little while (800k+ points) and spends a bit of memory, but the real problems start when I'm building new arrays of faces and edges. Pseudo-code:

points=all vertices

triangles=initial triangle

done_triangles=#()

edges=#()

for i in 1 to points.count do

(

for j in triangles.count to 1 by -1 do

(

if points[i] is within circumcircle of triangles[j] then

(

append edges all three edges of triangles[j]

deleteItem triangles j

)

else if circumcircle of triangles[j] is entirely to the left of points[i] then

(

append done_triangles triangles[j]

deleteItem triangles j

)

)

iterate through edges and remove all edges that appear twice

for (remaining edges) do append triangles for each edge + points[i]

)

for i in (any remaining triangles) do append done_triangles triangles[i]

new_obj=mesh vertices:points faces:triangles

There is also a function to calculate circumcircle center and radius. This code leaks memory at a phenomenal rate; I have 12 gigs of RAM, and it's all gone by the time I reach around 20k points. I have turned undo off, and tried using gc(), but the problem persists.

As far as causes for memory leaks go, I can only see the two main arrays (triangles and edges) and their append and deleteItem methods.

I've updated MAX with the latest service packs and hotfixes, but interestingly, when I try the code in MAX 2010, there is no memory leak... but it's dead slow!?

Does anyone have any ideas?

points=all vertices

triangles=initial triangle

done_triangles=#()

edges=#()

for i in 1 to points.count do

(

for j in triangles.count to 1 by -1 do

(

if points[i] is within circumcircle of triangles[j] then

(

append edges all three edges of triangles[j]

deleteItem triangles j

)

else if circumcircle of triangles[j] is entirely to the left of points[i] then

(

append done_triangles triangles[j]

deleteItem triangles j

)

)

iterate through edges and remove all edges that appear twice

for (remaining edges) do append triangles for each edge + points[i]

)

for i in (any remaining triangles) do append done_triangles triangles[i]

new_obj=mesh vertices:points faces:triangles

There is also a function to calculate circumcircle center and radius. This code leaks memory at a phenomenal rate; I have 12 gigs of RAM, and it's all gone by the time I reach around 20k points. I have turned undo off, and tried using gc(), but the problem persists.

As far as causes for memory leaks go, I can only see the two main arrays (triangles and edges) and their append and deleteItem methods.

I've updated MAX with the latest service packs and hotfixes, but interestingly, when I try the code in MAX 2010, there is no memory leak... but it's dead slow!?

Does anyone have any ideas?