Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solid Tools creates Memory Leak when used in loop #107

Open
hankbinkle opened this issue Jul 31, 2018 · 8 comments
Open

Solid Tools creates Memory Leak when used in loop #107

hankbinkle opened this issue Jul 31, 2018 · 8 comments

Comments

@hankbinkle
Copy link

hankbinkle commented Jul 31, 2018

  1. SketchUp/LayOut Version: SU2018 Pro (Sketchup.version_number = 1800016976)
  2. OS Platform: Mac OSX High Sierra 10.13.6
    MacBook Pro (Retina, 15-inch, Early 2013)
    NVIDIA GeForce GT 650M 1024 MB
    Intel HD Graphics 4000 1536 MB
    2.4 GHz Intel Core i7
    8 GB 1600 MHz DDR3
    (however also re-producable on other Mac setups)

Describe briefly what you are doing and what is happening.

Wanted to take a group containing many solid sub groups and union ALL of them by looping through each of the group's entities.

Describe what the expected result is.

The expected result would be a single group that has been unioned.

What happens: the operation will appear to complete, printing the appropriate time elapsed to the console, but then SU will lock up, with the spinning rainbow cursor. During this time, observing the memory usage in the Activity Monitor in this “afterward” period, Sketchup starts with at about 120 MB allocated and continues to jump upward by about 25MB increments until it peaks at 440 MB when SU finally begins to react again. The operation will be successful but will have hung for a long period. Sometimes SU will crash outright if too much geometry is fed into solid_ops_all_entities. Running the same operation with Enroth Union (commented out below) is almost instantaneous.

I have 8 gig of RAM, 3.4 of which is allocated when I start this operation and 4.5 when complete.

def solid_ops_all_entities(group_in)

    Sketchup.active_model.start_operation('Union All Entities', true)

    time_start = Time.now

    if(group_in.entities.length>1)

        # convert entity list into array
        temp_solid_array = group_in.entities.to_a

        # remove the first member from of array and define as new variable
        solid_result = temp_solid_array.shift

        # run union on each item in remaining array
        temp_solid_array.each{|item|
            if item.is_a? Sketchup::Group
                next unless item.valid? && item.manifold?
                #print "ATTEMPTING TO PERFORM SOLID OPERATION ON #{item} AND #{solid_result}\n"
                solid_result = item.union(solid_result)
                # Enroth on the other hand works fine.
                #Eneroth::SolidTools::SolidOperations::union(solid_result,item)
            end
        }

        # output results
        if(solid_result)
            solid_result.name = 'SOLID_RESULT'
            print "SOLID OPERATION SUCCESSFUL\n"
        else
            print "Solid Operation Failed. Confirm Primatives are valid solids\n"
        end

        # clean up 
        temp_solid_array.clear

    end #end of length check
    
    time_end = Time.now
    
    print "TIME ELAPSED = #{time_end - time_start} SECONDS\n"
    
    Sketchup.active_model.commit_operation

end # end solid_ops_all_entities

Attach any relevant files.
solid_tools_memory_leak.skp.zip

@DanRathbun
Copy link

A "memory hole" has nothing to do with software ...
https://en.wikipedia.org/wiki/Memory_hole

As said in the public forum, it is called a memory leak ...
https://en.wikipedia.org/wiki/Memory_leak

@hankbinkle hankbinkle changed the title Solid Tools creates Memory Hole when used in loop Solid Tools creates Memory Leak when used in loop Jul 31, 2018
@hankbinkle
Copy link
Author

hankbinkle commented Jul 31, 2018 via email

@thomthom
Copy link
Member

Title describe a memory leak, but the description seems to indicate unexpected result in how the geometry appear after boolean operation.

If this issue is related to unexpected boolean union, can you attach screenshots that indicate what you see and what you expect?

If it's a report on memory leak, can you describe how you detect and measure the memory leak?

@hankbinkle
Copy link
Author

Sorry, I will update behavior above.

@DanRathbun
Copy link

@thomthom
Copy link
Member

thomthom commented Aug 3, 2018

Just to clarify; the issue is the hang/freeze after the solid operation, and the occasional crash?

Memory consumption here doesn't appear to be the main issue. (Also, a memory leak is allocated memory not freed. Just because memory usage increase doesn't mean there is a leak. When you do a lot of geometry changes it will add to the undo stack - which is kept in memory.)

Running the same operation with Enroth Union (commented out below) is almost instantaneous.

So her union version never show the issues you describe? (I'll have to ask her for insight on what she is doing.)

@hankbinkle
Copy link
Author

hankbinkle commented Aug 3, 2018

Hello Thom,

correct... the issue is AFTER things seem to have completed.

I suggested memory issues based on input from Dan Rathbun in this post:

https://forums.sketchup.com/t/what-is-causing-this-script-to-hang/71421/3

I have no idea and certainly don't understand enough about how resources are allocated to do anything other than pass on Dan's wisdom!

Correct... Enroth's routine worked perfect. No hanging.

Thanks!

@DanRathbun
Copy link

The post is actually here:
https://forums.sketchup.com/t/what-is-causing-this-script-to-hang/71421/29
... and it is just a guess as I do not have (nor likely ever will have) a Mac to actually test on.

I also wondered in that post about SketchUp's autosave feature, and asked whether the model file was local or network (DropBox, etc.)

Reviewing the topic thread, I do not see an answer to these questions.

@thomthom Just to clarify; the issue is the hang/freeze after the solid operation, and the occasional crash? Memory consumption here doesn't appear to be the main issue.

I think it is a symptom of the problem. There is something happening that is taking time, blocking SketchUp and using memory.

Ruby's garbage collection could also be kicking in after so many changes but shouldn't be taking 40 seconds. We'd also think that a save operation would complete in a few seconds if the save is to a local file.

It is weird that he tried it on the same machine, under SU2015 and did not have the issue.

@thomthom Also, a memory leak is allocated memory not freed. Just because memory usage increase doesn't mean there is a leak.

In the following post Hank explains what the begin and end memory states were, ... but does memory ever return to the before levels ?
https://forums.sketchup.com/t/what-is-causing-this-script-to-hang/71421/26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants