0

I am having issues with what appears to be a memory leak. When I run my code, the memory usage keeps increasing until the application crashes.

I have been using the GC.start to be sure that all the unused objects are removed. I am also using the ObjectSpace module to track down the culprit, but I have not been able to understand what's happening.

In this file https://www.dropbox.com/s/0j75ylcsj3rs0ro/Log_1.txt I have logged the output of ObjectSpace count_objects. The first output from the command is before one big for-loop. At the end of each loop I use GC.start. From what I see, the total number of object stays constant during the for-loop, however the memory used by the application keeps increasing.

A stripped down version of the code is at this link https://www.dropbox.com/s/5fnludxurs1ljy8/Shading.rb

sawa
  • 165,429
  • 45
  • 277
  • 381
Rojj
  • 1,170
  • 1
  • 12
  • 32
  • I just get "This webpage is not available". Can you post at a service like gist instead - which require no downloads: https://gist.github.com/ – thomthom Aug 11 '14 at 10:38
  • here it is https://gist.github.com/Rojj/63c808456a2479e6c068 – Rojj Aug 11 '14 at 11:05
  • Does the memory usage peak only in SketchUp? Or does it also happen in standalone Ruby? – thomthom Aug 11 '14 at 11:51
  • Actually I do not have ruby standalone. I use it only in SU. – Rojj Aug 11 '14 at 12:00
  • Is it possible that the three nested loops are causing this issue? I was reading that it is a good practice to minimize the number of loops. Maybe I could change the inner loop with a function, that will be probably deleted after each call? – Rojj Aug 12 '14 at 06:46
  • 1
    Problem solved! I have learned that if you use variables with capital letters they are considered constants and, apparently, even if you reassign them memory is never freed. I had 5 variables beginning with capital letters and I was reassiging them a few million times in the loops. Changing to lower case has solved the problem. No more memory issues. – Rojj Aug 12 '14 at 08:06
  • Yea, I noticed that, but I didn't realize it didn't clear up the old values when reassigned. That's good to know. You should post that as an answer to your own question so it's easier to find the solution in case someone else has the same problem. – thomthom Aug 12 '14 at 08:42

1 Answers1

1

Problem solved! I have learned that if you use variables with capital letters they are considered constants and, apparently, even if you reassign them, memory is never freed. I had 5 variables beginning with capital letters and I was re-assigning them a few million times in the loops. Changing to lower case has solved the problem. No more memory issues.

Rojj
  • 1,170
  • 1
  • 12
  • 32