Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating Ruby time object causing garbage collection problem
    text
    copied!<p>I am an absolute newbie without even a computer science background. I am just a mechanical engineer trying to implement a way to remotely monitor the power output (and other output data) of the inverters in the solar power systems we install. So if I say anything exceedingly dumb, I apologize in advance. </p> <p>I'm trying to write a little ruby program that will live in my ror website's database folder. Every 15 minutes (for as long as the system is online producing energy), I want it to poll the data from our customers' inverters (via TCPSocket connection to a gateway connected to customer inverter) and update my website's database file with the new data. The loop I have looks something like this:</p> <pre><code>last_min = Time.new.min while(1) do tsec = Time.new.sec tmin = Time.new.min if ( ( tsec == 0 ) &amp;&amp; ( tmin - last_min == 1 ) ) # test using one minute # poll inverters, update database last_min = tmin end end </code></pre> <p>When I ran it at first, it threw a Segmentation Fault error. Then i put <code>GC.disable</code> up top and it worked fine (until I force quit only after a couple of min), but that was just to see if it was a garbage collection issue which it is and it seems to be the first creation of a time object that triggers the issue (throws the segmentation fault error). I know I obviously can't have garbage collection disabled for an infinite loop. But how do I "clean up after myself" with ruby? Can I free those time objects somehow at the end of every run through the loop? I saw a post about <code>GC.start</code>, but couldn't quite understand how that works. </p> <p>Also is there a way to run my program and see how much RAM it's using as it goes? I would appreciate any and all advice anyone could offer me here. (Including advice about the general architecture of the solar power output monitoring system I described in the beginning!) </p> <p>I have already deeply benefited from looking at all of the posts on here in my journey thus far and I thank you in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload