Euphoria Ticket #801: Translated program with insert() in a for-loop expansively consumes memory

Again, a simple program:

include std/console.e  
  
procedure test(integer n) 
    sequence objs = {}  
    puts(1,"Inserting...\n") 
    for i = 1 to n do 
        objs = insert(objs, rand(1000)/10, rand(length(objs)+1)) 
    end for 
    any_key() 
    puts(1,"Removing...\n") 
    for i = 1 to n do 
        objs = remove(objs, rand(length(objs))) 
    end for 
    puts(1,"Success!\n")  
end procedure  
  
test(1E4) 
  
any_key() 

Executed with interpreter it consumes only about 10 MB. But translated it consumes nearly 200 MB!

A real program that inserts 100000 elements complitely hangs my notebook.

euc version:

Euphoria to C Translator v4.0.5 
   Windows, Using Managed Memory 
   Revision Date: 2012-10-11, Id: 362497032f33 

gcc version 4.6.2

Platform: WinNT, Build: Windows7, Service Pack 1:2

Details

Type: Bug Report Severity: Normal Category: Translator
Assigned To: mattlewis Status: Fixed Reported Release: 4.0.5
Fixed in SVN #: View VCS: none Milestone: 4.0.6

1. Comment by mattlewis Oct 22, 2012

Prior to the call to Insert(), the translated code adds an extra reference to the sequence into which the new data is inserted. We shouldn't be doing this if it's the same sequence as is being assigned and if it's unique. A check for this needs to be added to translated code (see the interpreter implementation).

As a workaround, for this case, comment out / delete the line (should be line 71 from the example code) that adds the reference:

        { 
            s1_ptr assign_space; 
            if (IS_SEQUENCE(_7666)) 
            RTFatal("Third argument to splice/insert() must be an atom"); 
            insert_pos = _7666; 
            if (insert_pos <= 0){ 
                Prepend(&_objs_13677,_objs_13677,_7663); 
            } 
            else if (insert_pos > SEQ_PTR(_objs_13677)->length) { 
                Ref( _7663 ); 
                Append(&_objs_13677,_objs_13677,_7663); 
            } 
            else { 
                Ref( _7663 ); 
//                 RefDS( _objs_13677 ); 
                _objs_13677 = Insert(_objs_13677,_7663,insert_pos); 
            } 

2. Comment by Insolor Oct 24, 2012

Ok, without the RefDS() it doesn't devour the memory.

3. Comment by mattlewis Oct 24, 2012

See: hg:euphoria/rev/1bc9d7682793

changeset: 5792:1bc9d7682793 branch: 4.0 parent: 5787:b589513e4414 user: Matt Lewis date: Mon Oct 22 20:15:21 2012 -0400 files: docs/release/4.0.6.txt source/compile.e description:

  • fix memory leak for translated insert in place
  • fixes ticket 801

4. Comment by mattlewis Oct 24, 2012

See: hg:euphoria/rev/70a08419eeff

changeset: 5795:70a08419eeff branch: 4.0 parent: 5792:1bc9d7682793 user: Matt Lewis date: Tue Oct 23 14:26:16 2012 -0400 files: docs/manual.af source/compile.e source/eutest.ex description:

  • more memory leak fixes for insert
  • fixes ticket 801

5. Comment by mattlewis Oct 24, 2012

See: hg:euphoria/rev/abe7ce95d0e0

changeset: 5796:abe7ce95d0e0 parent: 5793:934f8d53434a parent: 5795:70a08419eeff user: Matt Lewis date: Wed Oct 24 11:50:42 2012 -0400 files: docs/manual.af source/compile.e source/eutest.ex description:

  • fix remaining leaks for other datatypes in translated insert()s
  • fixes ticket 801 for good

Search



Quick Links

User menu

Not signed in.

Misc Menu