What causes sticky library to clear in GhPython?

I noticed that at times scriptcontext.sticky library clears its contents. Not sure what triggers that. Does anybody know what are the causes for clearing contents of sticky? Other than recompute of course. Does switching between docs matter? (sc.doc switching between rhinodoc.activedoc and ghdoc)

Hi @Will_Wang

There is no code in GhPython that manually clears scriptcontext.sticky.
It’s possible a plug-in or a script of yours is doing that.

Thanks,

Giulio

–
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

How can a plug-in or script clear it if it is not possible to clear it with code? Sounds like an oxymoron.

There’s no oxymoron. I said that there’s no code that manually clears it. Any code can theoretically call sitcky.clear() and clear it. Sticky is a 100% compliant dict.

Here you can learn more about clearing a dict.

Can I use that to clear a particular one?

You should basically never do that. Only del your own entries if appropriate.
If you have more questions, please start new threads.

1 Like

I think I might have written messy scripts that causes memory leak (my naive guess)
I have not written scriptcontext.sticky.clear() anywhere but it’s cleared at times. Also with rhinoscriptsyntax I noticed the series of rs.Add*() inadvertently “bake” into my rhino model even when they are only run in GhPy and ghdoc

When you have a sample that can repeat the problem, I’ll be happy to look at it.

It’s likely that some of your or third-party scripts have some bugs that cause the particular variable you wish to use to be deleted, the script context being diverted to Rhino, sticky to be cleared, or something similar. If you can exactly spot when that happens (a memory leak is not enough, there must be a specific instruction), you’ll discover the key to finding the cause.

You are probably right. Everything is through HumaUI and I’ve scripted buttons to retrieve objects in rhinodoc. If I somehow manage to isolate a sample script that reproduces the problem and doesn’t require NDA with my boss, I’ll let you know. Thanks!

I’ve written some scripts in GhPy components replacing all rhinoscriptsyntax with RhinoCommon and it seems to fix the unexpected baking. There is no explicit doc switch in the script so I’m not sure why rs is pointed to RhinoDoc.ActiveDoc

Works for me now but would love to learn more about it.

Sorry, there’s not much we can do without a sample we can repeat.