PDA

View Full Version : MEL Optimization


petemolinero
10-24-2010, 07:40 PM
Hey,

I've been working on a procedural tree modeling script. This uses recursion, sometimes with reasonably high levels of depth. This means that there are sometimes hundreds of values stored in arrays.

I can generate one tree fine, and even a few more after that. But after several trees my whole computer starts to get slow, and then if I continue after that it crashes Maya. It is NOT a polycount issue, since when it crashes sometimes there are less than 10,000 faces, which my computer has absolutely no issue with during other use.

My only thought is that it is a memory leak somewhere?

In any case, I'm just wondering about optimization in maya. It seems like somehow there is something that is building up in memory and not getting erased after the function is run each time.

Does anyone know what this issue might be? As a general rule, how do you guard against this in MEL?

Thanks!

-Pete

NaughtyNathan
10-24-2010, 10:53 PM
I found a really odd and quite terrible issue in Maya (I think it was 2010, but I probably checked it in 2008 or 8.5 also, don't really remember?). I had a loop in which I was simply performing a uv relax and an optional vertex average many times on a selected mesh. at each iteration through the loop I would perform one uv untangle, one vertex average and then a delete history. Maya was fine for a couple of runs, then got slower and finally crashed, which sounds much like you are seeing with your script Pete.

I opened up Windows Task Manager and watched the RAM usage while I ran the script. Maya started on about 200Mb, and every time I ran my script it went up by 800Mb and didn't come back down. after it got to about 3.8 Gig of used RAM Maya simply gave up and crashed. I tried everything to debug it, (the script was only about 8 lines of MEL in the end) and I finally found out what it was when I removed the delete history part. If I DIDN'T delete history every iteration in the loop Maya stayed on a steady 220Mb RAM no matter how many times I ran the process, but as soon as I made it keep deleting the history RAM usage shot up massively until crashing.

I think it's safe to say that describing this as counter-intuitive is rather an understatement.

:nathaN

petemolinero
10-24-2010, 11:29 PM
Yup, that is exactly the issue I was having. And I had delete history in the loop, too, assuming that it would help. That is really interesting that it performs that way; I wonder if it has something to do with saving an 'undo' state for the proc?

I'll figure out a workaround, now that I know what the issue is. Thanks a bunch!

-Pete

jschieck
10-25-2010, 03:15 AM
try out flushUndo in your loop, fixed a similar problem i was having and kept ram usage at a reasonable level

NateH
10-25-2010, 04:41 AM
Yeah, the undo queue is probably filling up. you can flush it, or better yet, turn it off first with the -swf flag and then restore at the end. That way your user gets to keep their prior undo history.

petemolinero
10-25-2010, 02:44 PM
Awesome, great ideas. I'll give that a try as soon as I get a chance!

petemolinero
10-28-2010, 04:00 AM
Yeah, the undo queue is probably filling up. you can flush it, or better yet, turn it off first with the -swf flag and then restore at the end. That way your user gets to keep their prior undo history.

Nate, can you elaborate on how to turn off the undo queue using the -swf flag? I'm having trouble finding documentation on it.

jschieck
10-28-2010, 05:05 AM
the command is undoInfo -swf 0 to turn it off

petemolinero
10-29-2010, 05:09 PM
Thanks, I'll try that out!

Robert Bateman
10-29-2010, 06:37 PM
My only thought is that it is a memory leak somewhere?

Yup. It's called undo ;)


In any case, I'm just wondering about optimization in maya. It seems like somehow there is something that is building up in memory and not getting erased after the function is run each time.

Undo.


Does anyone know what this issue might be? As a general rule, how do you guard against this in MEL?

Disable/Re-enable the undo queue using undoInfo. The only other bit of nastiness is printing into the script editor (which also creates a memory leak)

CGTalk Moderation
10-29-2010, 06:37 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.