ZBrushCentral

Question: Seems to be a memory leak in ZScript

Try Running this Script and see if you get a memory leak too.
Just Open up Taskmanager (windows) and you can see what is happening.
Not too good. I have narrowed it down to The [IShowActions…] Function.
At least where it is placed in the code seems to change the mem. Try in and out of the loop. If you let the script run through the whole cycle it will give a readout of memUsage. Top Notebar is cycle.

I am interested if different platforms have the same problems:
PentiumIV 3Ghz
WinXP SP1
Motherboard Shuttle
2Gb RAM
NVIDIA Quadro Fx 980

My MemLeak Range is .3Mb to 1.2Mb per run. Starts Low and Raises each time. Let me know what you guys get.

[VarDef,Looper,1]// Define A Counter
  [VarDef, Mem, 0]// initial mem
  [VarDef, Tmp, "OK"]//final mem output
  [VarDef, Diff,0]//difference in mem usage
  [VarDef, LastRun, 0]
  
  //ZBrush\Scripts\MemoryLeak_Test_01.TXT
  ===========  Test To See Why Memory Leaking  ===========
  Cant Find Why/Where The Leak Is Occuring (Try For Yourself)
  Seems like the IShowActions Func has something to do with it
  With IShowActions about 60K per TaskUpdate, if in loop 120K (approx)
  Open Task Manager And Watch The Memory Raise As Looping Occurs ????
  PRESS ESCAPE To Stop
  [IButton,"Test Memory Leak", "Open Task Manager And Watch The Memory Raise As Looping",
  	
  	[VarSet, Mem, [ZBrushInfo, 3]]// get initial memory
  	[VarSet, Looper, 1]
  	
  	[IShowActions,0]// This seems to add more memUsage.//place it in loop and it doubles
  	
  	[Loop,10000,
  		[VarSet,Looper,[Var,Looper] + 1]//Increment Looper Variable
  		[NoteBar, Looper, [Var,Looper]/9999 ]// visual for testing
  		
  		[ISet,Draw:Draw Size,SIN(Looper)*256]//Just so something is happening
  		
  		[if,Looper > 9999,//999999
  			[VarSet, Looper, 1]
  			[LoopExit]
  		]
  		
		//[LoopExit]//Sometimes if I uncomment this and recomment, it never gets inserted back And
      	//	    	then it will sometimes Crash after this
  	]// END LOOPING
  	
  	[IShowActions,1]// reset Show Actions
  	
  	//Output memory findings
  	[VarSet, Diff, [ZBrushInfo, 3]-Mem]
  	[VarSet, Tmp,
  		[StrMerge, 
  			"Starting Memory: " ,Mem,
  			" Mb
Ending   Memory: ",[ZBrushInfo, 3],
  			" Mb
Gained: ",Diff," Mb
",
  			"Last Run Gain: ", LastRun
  		]
  	]
  	[VarSet, LastRun, Diff]
  	//Ouput findings
  	[Note, Tmp]
  		
  ]
  =======END======  Test Leaking Memory  =======END=======

Hi,
i have tried your script and my system works well…no memory leak :slight_smile:

cameyo

PentiumIV 3Ghz
WinXP SP2
Motherboard Abit
2Gb RAM
NVIDIA Quadro Fx 1000

I get the leak, much the same amounts, although sometimes there is zero gain (it goes up and down, doesn’t increase) and taking out Show Actions makes no difference.

My system:
Windows XP Pro SP2
AMD Athlon 1800 (1536 MHz)
ASUS motherboard
768 MB RAM

Cameyo:
Our computers are very similar, yet no leakage.
Very Strange. I am glad for you:)

marcus_civis:
I got zero a couple times, but it was when I was adjusting the script so I didn’t know if It was my computer or the variables.

Glad it is not just my computer, I always get worried when this kind of stuff happens.
I normally wouldn’t even check this, but lately I have really been working at getting all of the leaks out of my Graphics Apps. Just stumbled accross it.

If pixologic checks these posts, They should look into this.
Please, the more info the better. Would be interesting to get more data. Hmm, Maybe I should write a better script. One that outputs the data so everyone’s is comparable. Or at least gets The average loss per loop with the deviation. Oh well, its 5:15am…gotta go to sleep.

Anyone feel free to adjust the script to help solve the problem quicker. Just post your results and code.

Good Morning/night

Alright, After some sleep I have a new outlook for this.
Please Give a good look into my code and see if it is correct.
I just don’t want to declare a memory leak when it could just be faulty code.
I am fairly new to zscripting , so I know it is a possibility.

If it is my code, please let me know what corrections to make.

Thank you,

Chris Reid

Hi Chris,

Ran your code and no leak… Gained = 0 Mb.

My system: Dell 8200, 1.7, 512mb, XP Home with security updates only.

No idea what may be causing your result.

Sven

There is no memory leak nor is there anything wrong with your code.

After running your zscript go to the Zscript palette and press the Rec switch (Show Recorded ZScript). All the interface adjustments your script performed are there in text format. That is of course going to consume memory.

Press Zscript > End Rec and run your script again. No memory usage should occur. Undoable operations will also consume memory but your script does not contain any.

The memory overhead of allowing zbrush to record zscripts is minimal. Your 10000 draw size adjustments are not indicative of a standard zscript recording. I always let zbrush record zscripts automatically. It is perfectly safe.

Hey TV,

Good call. Just checked with record on…

I see how that could easily be perceived as a Mem leak. :wink:

Another gottcha.

Sven

Ah, likewise, no gain with Record off. Thanks TV. :+1:

TVeyes:
You did it again. Excellent catch.

No Memory Gain, problem solved. Glad that's all it is.

TVeyes:
Is there a way to pause the record if the user has it set on.

Like maybe a toggle before loop and a toggle after. Or some flag that will block script recorder.

The memory overhead of allowing zbrush to record zscripts is minimal. Your 10000 draw size adjustments are not indicative of a standard zscript recording.
The reason I am doing this is I need a while loop. Or some way to update information in the interface while getting mouse position data. When I am done getting data I exit. Well, I have an extreemly large For loop that runs now, giving the user plenty of time to make his/her decisions.
In fact now my script is calling to a dll in the while loop to get calculated data.
Just wondering how one would accomplish a while loop.

Chris Reid

Jumping in here - depends what you’re doing but could you not use the Sleep command?

I tried sleep and I don’t get any updates. It is a very different scenario than just a zscript. There are levels of windows that pass data back to the script. The only way for zbrush to update it for it to be running, unfortunately sleep stops the thread(or appears to). I have it working pretty good now. Im not too worried about it.

Thanks for the suggestion,

Chris