|
Post by turtleman on Feb 14, 2022 13:53:36 GMT -5
Without going into a whole lot of detail, my program uses several dozen textboxes of constantly changing numeric data. Each display was (past tense) accompanied by a corresponding flush command. I subsequently found this was causing the program to crash after several thousand updates, which brings me to the following question: Is there a way to monitor and clear memory used by flush?
I'm not sure I'll ever graduate beyond "Novice," but really appreciate the help I've received on this board. Thanks!
|
|
|
Post by Rod on Feb 14, 2022 14:17:04 GMT -5
Easily sorted. But for starters textboxes don't need flush. So do you have graphics on display? It is graphics that consume memory. Lets assume you are drawing to a graphic box. Just flushing every time you update the graphic box keeps accumulating graphic segments. What you need to do is either CLS prior to your update or more refined, del segment prior to flushing. That way segments do not accumulate but you still get the benefits of the graphics sticking if covered by another window or if your window is minimised and restored. A small extract of a single update would let me show exactly how to manage the segments. The trick to it is deleting the correct segment, naming segments can help. There are also a couple of articles on the LBPE which cover the subject quite well. alycesrestaurant.com/lbpe/SegmentsAndFlushing.htmlThis is one I did but since we have lost the graphics in the tutorial it has lost a bit of meaning. alycesrestaurant.com/lbpe/Graphic%20Segments.html
|
|
|
Post by turtleman on Feb 14, 2022 14:24:13 GMT -5
Thanks Rod. Whoops – I goofed! I'm using graphic boxes instead of textboxes to display the data in order to change colors if the data is positive, negative, or zero. I also have a couple dozen graphic boxes used as "LED" indicators.
|
|
|
Post by Rod on Feb 14, 2022 16:19:42 GMT -5
Ok, when you flush in your current code you need to change each flush to flush to a named segment. The name should be unique to each graphicbox. Then it is simply a case of preceding the flush statement with a delsegment statement using the name.
It does not matter that first time through the named segment does not exist.
I often just work with one large graphic box to simplify segment handling.
|
|
|
Post by turtleman on Feb 15, 2022 4:52:09 GMT -5
Thanks again, but to say I'm merely confused would be an understatement. The snippet below is one of many examples:
if statsfinal > 0 then #stats.final, "down; fill lightgray; color green; backcolor lightgray" if statsfinal < 0 then #stats.final, "down; fill lightgray; color red; backcolor lightgray" if statsfinal = 0 then #stats.final, "down; fill lightgray; color blue; backcolor lightgray" #stats.final, "place 2 13; font arial 9 bold " #stats.final, "\" ;statsfinal #stats.final, "flush"
The "lightgray" is used to hide the graphicbox so only the number is shown in green, red, or blue. In other instances, the background color changes, but of course, the flush problem remains the same.
The "problem" occurs when the code is run many thousands of times and crashes due to the abundance of flushes. Can you show an example where "deselect" gets inserted? Whatever I'm trying isn't working.
As a crude workaround, I can selectively flush when the program has completed or manually paused, but have no idea how many flushes can be used this way. So getting back to my original question - is there a way to monitor how much memory is being used and then cleared wholesale?
|
|
|
Post by tsh73 on Feb 15, 2022 7:12:53 GMT -5
Try this flush/segment relaterd lines are indented (3 lines) Run TaskManager, find JB, watch memory usage as you run it Now compare with delsegment line commenten on (will likely crash)
graphicbox #stats.final, 10, 10, 200, 50
open "flush test" for window as #stats #stats "trapclose [quit]" #stats.final, "flush stats.final" 'first time needs something to delsegment?
while 1 SCAN
statsfinal = int(rnd(0)*3)-1
if statsfinal > 0 then #stats.final, "down; fill lightgray; color green; backcolor lightgray" if statsfinal < 0 then #stats.final, "down; fill lightgray; color red; backcolor lightgray" if statsfinal = 0 then #stats.final, "down; fill lightgray; color blue; backcolor lightgray"
#stats.final, "place 2 13; font arial 9 bold " #stats.final, "\" ;statsfinal #stats.final, "delsegment stats.final" #stats.final, "flush stats.final" wend
[quit] timer 0 close #stats end
|
|
|
Post by Rod on Feb 15, 2022 9:37:23 GMT -5
Not to confuse but to be sure we are clear. If you have multiple graphicboxes then you need to delsegment multiple times. You will need the code Tsh73 shows for every graphicbox you have on display. So I doubt you can do it when you pause or when the program completes since every graphicbox needs managed. Also, and this is very important, you can't delsegment AFTER a flush, you must do it before you issue the flush command.
If you try and delsegment after you flush you have moved on to a new segment and the older one will still persist in memory.
But it is a simple fix, do it like Tsh73 shows.
|
|
|
Post by Walt Decker on Feb 15, 2022 18:07:30 GMT -5
Just to confuse the issue, if you are not concerned about whether the graphic is persistent you can use "discard" (#main.gfx, "discard") to clear memory.
|
|
|
Post by Rod on Feb 16, 2022 2:30:20 GMT -5
Discard will not clear a previously flushed segment. It will only clear the currently building segment. So as you say if you never flush it is is often useful but in this case we are flushing to make the update persist. On the next update we must delsegment then flush again. Discard would leave the segments building and it would still crash.
|
|
|
Post by turtleman on Feb 16, 2022 11:37:38 GMT -5
I sure wish I had posted my flush-related question years sooner. Thanks a lot guys! I had come across delsegment before, but didn't have a good understanding of its use and importance. The flush/segment program from tsh73 was eye-opening; and as is often the case, a simple example is worth 10,000 words! What a difference! Being able to program (a little) in Liberty Basic, I can't help wondering if flush/delsegment is necessary with other languages. Thanks again everyone!
|
|
|
Post by Carl Gundel on Feb 16, 2022 12:52:43 GMT -5
I sure wish I had posted my flush-related question years sooner. Thanks a lot guys! I had come across delsegment before, but didn't have a good understanding of its use and importance. The flush/segment program from tsh73 was eye-opening; and as is often the case, a simple example is worth 10,000 words! What a difference! Being able to program (a little) in Liberty Basic, I can't help wondering if flush/delsegment is necessary with other languages. Thanks again everyone! The segmented drawing model that Liberty BASIC uses is actually built on top of the metafile drawing features that are built into Windows. If that didn't exist I certainly would not have done graphics that way. In fact with Liberty BASIC 5 I had to write my own version of that in order to make graphics drawing portable across operating systems. Segmented drawing is useful for some things, but if it wasn't there probably nobody would miss it.
|
|