How to check variable memory in GHpython

Hi all.
May I ask how to check the true memory of var in GHpython?

Currently all of them are showing “16”…

You’re asking the size of a variable. In Python there is no direct way of getting memory addresses, and to be honest I don’t see why you would need that. Accessing memory you’re not supposed to leads only to instability.

hi Nathan. Thanks for your quick reply.

I am running the iteration algorithm and in the end, I run out of memory (16G).

So I am checking how I should check that variable memory so that I can control the memory usage and delete some of them explicitly if they occupy too much.

You’re working in a .NET environment so you will have to work with that. Directly manipulating memory is not going to help you with that.

With IronPython you work with both Python and .NET, since IronPython is a .NET implementation of Python.

Look for recursion and ask if you need it to be implemented the way it is now. Regular recursion suffers easily stack overflow and memory problems you mention, see if tail recursion helps.

And of course in general check how you are saving data.

Anyway, without seeing any code it is going to be hard to give more suggestions.

Not sure if it helps but last time I had a Python script using a lot of memory, I figured it related to the fact that it keeps the whole execution in the undo stack, which means you can undo the executed script after it has run.
What I ended up doing is to run a ClearUndo after each iteration.

1 Like

Hey. I am overriding those destructor functions for each of my customize classes.

At the bottom of the destructor functions I will call " sc.doc.Objects.Delete(guid,True)" to delete guidobject.

So that I can explicitly delete the unused class instance.

But currently, it didn’t show the success msg…

Hi. Thanks for your suggestion.
May I know how to find and call it? I mean which lib I should import?

1 Like

It seems I need to call gc as well. It seems be the solution.

Correct. In .NET the other alternative is to implement IDisposable, then explicitly call Dispose. I am not sure how to do that in IronPython, though.

1 Like

Hi Nathan. May I ask you more about how to do it in C#.


The final output is the circle GUID in doc.
The syntax doc.Objects.AddCircle(s) is to convert the circle constructor into GUID and write it to doc.

My confusion is, then How should I delete the Constructor: center(Point3d) and c(Circle) in this case?

I mean, if these constructors are still taking the memory I do want to release them.

Or Like in this case, the return type is Point3d , if I am able to get its GUID then I can delete it from doc.

Will be grateful if you can answer it. Thank you so much.

I did a few experiments and found the difference between GhPython and Gh C#.

In python , even though the return type is Point 3d. It will automatically add a GUID to the sc.doc. (And I am not able to get this GUID)

In C#, the type Point 3d will store somewhere else, and only add a GUID into Rhino.RhinoDoc.ActiveDoc after I call Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint()

Also, wonder will the constructor type will be cleaned by default gc?