LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help in finding memory leaks / problems

Hello,

I'm building this simple CNC gcode sender and have recently refactored it and fixed a bunch of problems that folks such as @GerdW and others have suggested, it was a huge help and now the code is working much better.  However when I run the code for a long while (for example when reading in a full gcode file with thousands of entries), it eventually will crash.  Generally it's a no warning shutdown of the whole NI environment, sometimes it has said it ran out of memory without much more detail.

 

I am figuring it's something having to do with not handling memory very well and am hoping you might help me track down what I'm doing poorly?

Thanks for the help!

0 Kudos
Message 1 of 11
(2,263 Views)

Hi JFWM,

 

again you are uploading VIs using the latest LabVIEW version. By downconverting you can reach far more people to help you… (I still prefer LV2017.)

 

More suggestions:

  • You should create a LabVIEW project to organize your VIs and CTLs.
  • You may attach single files, but it is appreciated when you just ZIP your project folder, which should contain all VIs/CTLs/other stuff along with the lvproj file!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(2,255 Views)

Yep, thanks, here it is in LV 15, zipped.

0 Kudos
Message 3 of 11
(2,239 Views)

Hi JFWM,

 


@JFWM wrote:

am hoping you might help me track down what I'm doing poorly?


Still bad code:

  • use more subVIs
  • apply the Style guide: straight wires, no sequence frames, especially not stacked ones, …
  • still a lot of BytesAtPort nodes, usually used wrongly, supported by as many wait functions…

Do you really need to plot all coordinates? How many points do you collect?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 11
(2,232 Views)

In your "Run GCode File" case there is potential for the X, Y and Z vector arrays to grow unbound. They are also duplicated in the plot VI so there are 6 arrays that grow every iteration unbound. That could eat up memory pretty quickly.

 

Also it looks like your "Open GCode File" case is.... wrong. The for loop makes no sense. Do you really want an array element for every character in the file?

Message 5 of 11
(2,203 Views)

I can add more subVIs (am doing so now), didn't know there was as a style guide so I'll look into that, and have been researching BytesAtPort and still am unclear as to how it should be used properly for this scenario.  If you have any more info on that it would be helpful.

 

This is all very good, thank you.  The last major LV build I did was using LV 7 + IMAQ Vision for a laser imager that found defects in solar cells and then excised them.  Which was night and day compared to the LV6 on mac I learned on.  It's been quite a while since then...

 

 

0 Kudos
Message 6 of 11
(2,202 Views)

Ah... so when it comes to memory you're saying having duplicative arrays that can grow infinitesimally large is a problem?!  Thanks. 🙂

0 Kudos
Message 7 of 11
(2,199 Views)

Even if they aren't duplicated, there is no limit on how large they can be. Duplicated just means you will run out of memory twice as fast. As I mentioned before I also think you are converting the file into an array of strings incorrectly. You are adding an element for every character in the file. That array also determines how big those vector arrays will be. 

 

Here's what you have versus what I think you want to be doing (Array 2)

Forums For Loop.png

 

The bytes at port is usually the wrong way to do serial communication. If you can, using the termination character is a much better way to do things. When used, the VISA read will read until it sees the termination character or it exceeds the timeout set. Using bytes at port doesn't guarantee a complete message. It may depend on the device you are talking too, but it looks like you append a carriage return when you send a message, so I would be surprised if it is not sending one back at the end of it's messages. Many devices use carriage return and line feed so the default line feed termination character might work just fine. The manual for the device should specify.

Forums Visa config.png

 

With the termination character working you can remove all the Bytes at port property nodes and data coming from the visa reads will contain a complete message.

 

 

Message 8 of 11
(2,192 Views)

Gotcha.  You're right on the 'open g code section', I just opened a bunch of test files and on a few of them your code churns it out correctly when my existing did not.  Thanks! 

I try removing all the bytes at port and seeing how it performs.  Thanks again!

 

As for the XYZ vectors, how can I minimize memory usage if I hold it true that they should be expandable to deal with whatever size thing they may see?  Or do I just give a cap and start overwritting points?

 

Also, on a modern desktop computer how many points are too many in a 3D plot? 

0 Kudos
Message 9 of 11
(2,171 Views)

Well each double is 8 bytes, there are 6 arrays so that's 48 bytes per iteration. You should be able to do almost 21,000 iterations before using a Gig. Not sure what a reasonable number would be in your case, but I would probably cap it at least at that. I doubt your plot is going to make any sense at that point anyway. 

0 Kudos
Message 10 of 11
(2,151 Views)