0; i++) { shape[i] = mdai->item[r].shape; } + xfree(mdai->type); xfree(mdai->item); xfree(mdai); return shape; Then, % ruby testna.rb 5964 pts/3 R 0:00 253 570 2445 1604 0.2 ruby testna.rb 5964 pts/3 S 0:02 260 570 7733 6920 0.9 ruby testna.rb 5964 pts/3 S 0:03 260 570 7733 6920 0.9 ruby testna.rb 5964 pts/3 S 0:05 260 570 7733 6920 0.9 ruby testna.rb 5964 pts/3 R 0:07 260 570 7733 6920 0.9 ruby testna.rb 5964 pts/3 S 0:09 260 570 7733 6920 0.9 ruby testna.rb Masahiro Tanaka [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <200402190503.OAA00565@koala.ir.isas.jaxa.jp> [ref] => <15db2cbe.0402180805.447bc44e@posting.google.com> [htmlstate] => on_nl2br [postusername] => Masahiro [ip] => masa@ir.isas.ac [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Weird GC behaviour or memory leak with NArray::to_na? - Ruby
Professional Web Applications Themes

Weird GC behaviour or memory leak with NArray::to_na? - Ruby

I have what appears to be a memory leak in my code, and I'm able to reproduce it using the following test code: require 'narray' a=Array.new(100,2) 200000.times{|x| #c=a.collect{|b| b+1} #This is OK. #a.collect!{|b| b+1} #This is OK. #a=a.collect{|b| b+1} #This is OK. #c=Array(a) #This is OK. d=NArray.to_na(a) #This results in huge memory bloat } Running this code shows my memory footprint increase monotonically from ~2M to >20M... I killed the process at this point. Any of the other commented lines would run with a stable memory footprint. However, if I add ObjectSpace::garbage_collect into the loop, everything is fine. Now to ...

Sponsored Links
  1. #1

    Default Weird GC behaviour or memory leak with NArray::to_na?

    I have what appears to be a memory leak in my code, and I'm able to
    reproduce it using the following test code:

    require 'narray'

    a=Array.new(100,2)
    200000.times{|x|
    #c=a.collect{|b| b+1} #This is OK.
    #a.collect!{|b| b+1} #This is OK.
    #a=a.collect{|b| b+1} #This is OK.
    #c=Array(a) #This is OK.
    d=NArray.to_na(a) #This results in huge memory bloat
    }

    Running this code shows my memory footprint increase monotonically
    from ~2M to >20M... I killed the process at this point. Any of the
    other commented lines would run with a stable memory footprint.

    However, if I add ObjectSpace::garbage_collect into the loop,
    everything is fine.

    Now to complicate matters further:

    require 'narray'
    a=Array.new(100,2)
    200000.times{|x|
    d=a.collect{|b| NArray.to_na([b,b])} #memory bloat despite explicit
    GC!
    ObjectSpace::garbage_collect
    }

    This exhibits the growing memory footprint problem...... Help? Note:
    I realize this example may be a little contrived, but my code does
    this plus some more, requiring (IMHO) this approach.

    Can someone explain this behaviour? I use the .to_na constructor a
    lot in my code, and really need to sort this out, otherwise I cannot
    run my code for longer than brief periods before my system comes
    crashing on down.

    Thanks, Jeff
    Sponsored Links
    Jeff Guest

  2. #2

    Default Re: Weird GC behaviour or memory leak with NArray::to_na?

    > I have what appears to be a memory leak in my code, and I'm able to 

    Hmm...

    % ruby -v
    ruby 1.8.1 (2003-12-25) [i686-linux]

    % cat testna.rb
    require 'narray'

    a=Array.new(100,2)
    system "ps v"
    5.times do
    200000.times do |x|
    d=NArray.to_na(a)
    end
    system "ps v | grep ruby | grep -v grep"
    end

    % ruby testna.rb
    PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
    5400 pts/3 S 0:00 253 570 2445 1600 0.2 ruby testna.rb
    5400 pts/3 S 0:08 257 570 17565 16736 2.1 ruby testna.rb
    5400 pts/3 S 0:16 257 570 25265 24436 3.1 ruby testna.rb
    5400 pts/3 S 0:25 257 570 33605 32776 4.2 ruby testna.rb
    5400 pts/3 S 0:33 257 570 41301 40472 5.2 ruby testna.rb
    5400 pts/3 S 0:41 257 570 49481 48484 6.3 ruby testna.rb


    Thanks, it is a bug.

    --- na_array.c 2003/03/03 11:15:28 1.5
    +++ na_array.c 2004/02/19 04:14:29
    -107,6 +107,7
    for (i=0; r-->0; i++) {
    shape[i] = mdai->item[r].shape;
    }
    + xfree(mdai->type);
    xfree(mdai->item);
    xfree(mdai);
    return shape;

    Then,

    % ruby testna.rb
    5964 pts/3 R 0:00 253 570 2445 1604 0.2 ruby testna.rb
    5964 pts/3 S 0:02 260 570 7733 6920 0.9 ruby testna.rb
    5964 pts/3 S 0:03 260 570 7733 6920 0.9 ruby testna.rb
    5964 pts/3 S 0:05 260 570 7733 6920 0.9 ruby testna.rb
    5964 pts/3 R 0:07 260 570 7733 6920 0.9 ruby testna.rb
    5964 pts/3 S 0:09 260 570 7733 6920 0.9 ruby testna.rb

    Masahiro Tanaka



    Masahiro Guest

  3. #3

    Default Re: Weird GC behaviour or memory leak with NArray::to_na?

    This problem was due to a memory leak in NArray 0.5.7. Updating to
    0.5.7p2 fixed the problem.

    Jeff
    Jeff Guest

Similar Threads

  1. #39438 [NEW]: Memory leak PHP Fatal error: Out of memory
    By nikolas dot hagelstein at gmail dot com in forum PHP Bugs
    Replies: 11
    Last Post: December 1st, 08:08 PM
  2. Weird ssh behaviour with 5.2
    By snogfest in forum AIX
    Replies: 6
    Last Post: January 13th, 07:11 PM
  3. Weird Behaviour Bug...anyone?
    By Richard in forum Macromedia Director Lingo
    Replies: 2
    Last Post: January 5th, 05:21 PM
  4. Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]
    By David Heinemeier Hansson in forum Ruby
    Replies: 4
    Last Post: September 10th, 01:58 AM
  5. Weird Variable Behaviour
    By Jerz in forum PHP Development
    Replies: 0
    Last Post: July 31st, 09:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139