PDA

View Full Version : Garbage Collection Error


DustinBrown
04-11-2012, 09:22 PM
I'm running into a garbage collection issue. I suspect the cause is a function I made which loops through meshes in my scene and automatically creates materials and fetches the proper texture maps. It's a pretty involved process - switching between SME and Compact ME to perform various operations, loading TGA files, etc.

I don't know how to find out, for certain, if this is the function that's causing the garbage collection error, but my gut tells me it is. The error occurs when I load the next scene to run the script on. I have over a hundred scene files I need to run the script on. I'm currently having to shut Max down between scene files, which sucks.

http://www.dustinbrown.com/wip/temp/msgc.jpg


I've tried adding gc() at the end of the function I believe to be the culprit, but that doesn't seem to have helped, I still the get error when I open the next scene file.

At this point I'm looking for suggestions of more surgical methods to avoid these sorts of errors. I've read the help doc's pages on memory management and garbage collection, which is good information. Also, this thread seems helpful:

http://forums.cgsociety.org/showthread.php?f=98&t=357942&highlight=garbage

Bobo's comment about "Possible causes: getting a mesh value inline or again and again without deleting it manually after the use, incremental string and array appending operations, bitmap value definitions inside the loop etc." has me interested in learning how to perform some of these manual operations to manage the memory profile for the script.

denisT
04-11-2012, 10:27 PM
first of all:
#1 how much initial heap allocation memory for max scripts do you have?
#2 do you open bitmaps during the script run?
#3 do you free opened bitmaps before loading new file?
#4 do you reset max file before loading the new one?

DustinBrown
04-11-2012, 10:46 PM
Thanks for the reply.

#1 how much initial heap allocation memory for max scripts do you have?

print heapSize
23373864L

#2 do you open bitmaps during the script run?

I'm not sure if bitmaps are being "opened" or not. To fetch the bitmap I'm using:

skinDiff = bitmapTexture filename:(maxFilePath+nnn+"color.tga")


Is that considered "opening" a bitmap? I don't see a bitmap selection dialog open when the script runs. I think it's just using the path and filename info I give it to go directly to the file.

#3 do you free opened bitmaps before loading new file?

Again, I'm not sure what is considered "opening" a bitmap, but no I'm not doing anything specifically to free bitmaps. According to the docs, gc does this among other things.

#4 do you reset max file before loading the new one?

I have tried this and I still get the garbage collection error.

denisT
04-11-2012, 11:06 PM
#1 how much initial heap allocation memory for max scripts do you have?

print heapSize
23373864L

#2 do you open bitmaps during the script run?

I'm not sure if bitmaps are being "opened" or not. To fetch the bitmap I'm using:

skinDiff = bitmapTexture filename:(maxFilePath+nnn+"color.tga")


Is that considered "opening" a bitmap? I don't see a bitmap selection dialog open when the script runs. I think it's just using the path and filename info I give it to go directly to the file.

#3 do you free opened bitmaps before loading new file?

Again, I'm not sure what is considered "opening" a bitmap, but no I'm not doing anything specifically to free bitmaps. According to the docs, gc does this among other things.

#4 do you reset max file before loading the new one?

I have tried this and I still get the garbage collection error.

#1 you have to add initial memory to be allocated. Go to the preference settings and set maxscript initial heap allocation to ~128 Mbytes
#2 you are opening bitmaps. so...
#3 free old bitmaps before loading new file. use freeSceneBitmaps() for that.
#4 try to do resetMaxFile() and DON'T do any gc()

DustinBrown
04-12-2012, 07:53 PM
I'll give that a shot, thank you!

jedie
04-14-2012, 09:23 AM
I'm running into a garbage collection issue.

http://www.dustinbrown.com/wip/temp/msgc.jpg


I had the same error some time ago... I haven't any bitmap stuff in the scene. It allways happens if i use "reset max". It was depending on which scene was open.

Solution: startup a fresh max, merge all objects from the problematic scene.

DON'T do any gc()
Is this a general tip? I use it on almost all scripts at the end...

denisT
04-14-2012, 12:42 PM
Is this a general tip? I use it on almost all scripts at the end...
reset the max scene does do garbage collection. we are looking for the most stable solution for the batch process. i just don't want to do gc two times in this case.

DustinBrown
05-18-2012, 11:22 PM
Apologies for the necro thread, but I'm still having GC problems and I believe I've narrowed the problem down to SME.

Similar threads I've found:
http://forums.cgsociety.org/showthread.php?t=929019
http://forums.cgsociety.org/showthread.php?f=98&t=357942

This is the code I have:

fn stripMats =
(
-- Remove material assignments on all objects in the scene
for obj in objects do
(
obj.material = null
)
-- COMPACT MATERIAL EDITOR
matEditor.mode = #basic -- Sets ME to compact mode
actionMan.executeAction 0 "50048" -- Tools: Material Editor
actionMan.executeAction 2 "40293" -- Material Editor: Cycle 3X2, 5X3, 6X4 Sample Slots
actionMan.executeAction 2 "40293" -- Material Editor: Cycle 3X2, 5X3, 6X4 Sample Slots
matEditor.Close()
macros.run "Medit Tools" "clear_medit_slots"
--freeSceneBitmaps() -- Clears all scene bitmaps out of memory
--saveMaxFile (maxFilePath+maxFileName)

-- SLATE MATERIAL EDITOR (SME)
matEditor.mode = #advanced
sme.deleteView 1 false -- Delete current slate in SME
newView = sme.getView(sme.createView "Character Materials") -- Make a new slate in SME
--actionMan.executeAction 0 "40130" -- Redraw all views
--max select none
--freeSceneBitmaps() -- Clears all scene bitmaps out of memory
--saveMaxFile (maxFilePath+maxFileName)
)


I've tried running each half of the function alacarte and I'm almost certain it's the SME stuff that's causing GC problem. I have set my initial heap allocation to 128MB under Preferences, but that hasn't helped at all. You can also see that I've been commenting out (essentially removing) things as a process of elimination to try to narrow the problem down. Even with the above things commented out I still get GC errors any time I reset the scene or try to open a new scene.

My workstation has 12GB of RAM, so memory shouldn't be an issue.

CGTalk Moderation
05-18-2012, 11:22 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.