Author Topic: [FIXED] Memory leak issue: PRINT Tab(x); USING...  (Read 1536 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3185
    • Steve’s QB64 Archive Forum
[FIXED] Memory leak issue: PRINT Tab(x); USING...
« on: October 22, 2018, 12:24:31 AM »
As was discussed here: https://www.qb64.org/forum/index.php?topic=624.15

I've did some digging into this issue, as reported, and it doesn't seem as if the blame for the problem actually falls on TAB.  It's some weird glitch with PRINT TAB(); USING which is causing the problem, as illustrated below:

Code: QB64: [Select]
  1.     PRINT TAB(1); USING "###"; count;
  2.     'PRINT TAB(1)
  3.     'PRINT USING "###"; count;

Run the program, watch in task manager as we continue to consume more and more memory.

Then, remark out the first line, unremark the next two, and watch as it runs and maintains a steady memory usage.

TAB doesn't seem to hold the glitch itself.  Neither does PRINT USING...  It's only when we use them together that we're seeing the problem.

More investigation to follow.
« Last Edit: October 29, 2018, 11:49:23 PM by odin »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3185
    • Steve’s QB64 Archive Forum
Re: Memory leak issue: PRINT Tab(x); USING...
« Reply #1 on: October 22, 2018, 12:42:17 AM »
The issue is here:

Code: QB64: [Select]
  1.     PRINT "BOB"; USING "###"; count;

(Ignore the $CHECKING:OFF; that's just to clean up the C translation so it's a little less much to dig through...)

Our translation looks like:

Code: QB64: [Select]
  1. tqbs=qbs_new(0,0);
  2. qbs_set(tqbs,qbs_new_txt_len("BOB",3));
  3. IF (new_error) GOTO skip340;
  4. makefit(tqbs);
  5. qbs_print(tqbs,0);
  6. tqbs=qbs_new(0,0);
  7. tmp_long=0;
  8. print_using_format340=qbs_new(0,0); qbs_set(print_using_format340,qbs_new_txt_len("###",3));
  9. IF (new_error) GOTO skip_pu340;
  10. tmp_long=print_using_single(print_using_format340,*__SINGLE_COUNT,tmp_long,tqbs);
  11. IF (new_error) GOTO skip_pu340;
  12. skip_pu340:
  13. IF (new_error){
  14. g_tmp_long=new_error; new_error=0; qbs_print(tqbs,0); new_error=g_tmp_long;
  15. qbs_print(tqbs,0);
  16. }
  17. qbs_free(tqbs);
  18. qbs_free(print_using_format340);
  19. skip340:

The problem here is semi-obvious once we take a look at the relevant portion of the code:

tqbs=qbs_new(0,0);
qbs_set(tqbs,qbs_new_txt_len("BOB",3));
if (new_error) goto skip340;
makefit(tqbs);
qbs_print(tqbs,0);
tqbs=qbs_new(0,0);

When we go to print "Bob", we create a new temp variable to save the string in (tqbs)...  Then we print it (qbs_print)...

Then we go to create another new temp string (tqbs again), without freeing the old one.

Simply remark out the line tqbs=qbs_new(0,0); where it appears the second time, and all is good to go.

PRINT USING is requiring the creation of that temp variable, even if it's been created already.

Change here is simple:

Either free tqbs before we create a new one, or else never create a new one at all.

********************

Now, the issue is, "Where do we go in QB64 to actually make the changes necessary to fix this memory leak?"
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3185
    • Steve’s QB64 Archive Forum
Re: Memory leak issue: PRINT Tab(x); USING...
« Reply #2 on: October 22, 2018, 01:07:01 AM »
Fix pushed to development build.  This shouldn't be an issue for us anymore.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1536
  • The best code is the DNA of the hops.
Re: Memory leak issue: PRINT Tab(x); USING...
« Reply #3 on: October 22, 2018, 09:41:51 AM »
Hi Steve. It seems to me that a small leak of memory has a mere loop DO: LOOP. After running this empty loop is quite fast, it stops after a while but slowly grows further when you click or drag the program window. Or is that so right?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3185
    • Steve’s QB64 Archive Forum
Re: Memory leak issue: PRINT Tab(x); USING...
« Reply #4 on: October 22, 2018, 11:22:34 AM »
No idea, but I'll play around with it later today to see if I can replicate any issue with DO:LOOP
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 411
Re: Memory leak issue: PRINT Tab(x); USING...
« Reply #5 on: October 25, 2018, 08:31:09 PM »
It makes me feel kinda special that my l'il old program brought this issue to light. ;)
Andy