The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Make a subtle memory leak

Last post 06-07-2013 5:31 AM by dhromed. 27 replies.
Page 1 of 1 (28 items)
Sort Posts: Previous Next
  • 10-12-2012 11:59 PM

    • Ben L.
    • Top 10 Contributor
    • Joined on 12-22-2010
    • Inventor of the 186-hour work week
    • Posts 3,607

    Make a subtle memory leak

    Your choice of language. Go.
  • Morbs is the smartest!
  • 10-15-2012 3:05 PM In reply to

    Re: Make a subtle memory leak

    List<object> myList = new List<object>();
    for (int i = 0; i < int.MaxValue; i++)
        myList.Add(new object());
    This is a signature. It's not a good one, but it's still a signature.


  • Mon, February 30 2010 2:64 PM

    • Fabulous Darth Vader
    • Top 10 Contributor
    • Joined a long, long time ago
    • In a Glittery galaxy far, far away
    • Posts π x 10-14


    I have cornified this post, pray I don't cornify it further.






  • 10-15-2012 4:20 PM In reply to

    Re: Make a subtle memory leak

     var exportBody = "";

    //you can't leak in a managed language, but you can fill that fucker right the hell up
    for (var i=0; i < fullDataRecords.length; i++) {
       var _record = fullDataRecords[i];
       for (var key in _record) {
          exportBody += _record[key] +' | ';
       }
    }

    In complex analysis, a meromorphic function on an open subset D of the complex plane is a function that is holomorphic on all D except a set of isolated points

  • 10-15-2012 8:25 PM In reply to

    • Ben L.
    • Top 10 Contributor
    • Joined on 12-22-2010
    • Inventor of the 186-hour work week
    • Posts 3,607

    Re: Make a subtle memory leak

    mott555:
    List<object> myList = new List<object>();
    for (int i = 0; i < int.MaxValue; i++)
        myList.Add(new object());
    In an ideal language, object would be a zero-width struct, which would make the last line of that increment length and do nothing else.
  • Morbs is the smartest!
  • 10-18-2012 2:52 PM In reply to

    Re: Make a subtle memory leak

    void TrimLeft(char *s)
    {
        char *n = new char[strlen(s)];
        char *p = n;
        do {
            if (*s != ' ')
                *p++ = *s;
            ++s;
        } while (*s);
        strcpy(s,n);
        delete[ n;
    }
    
    void foo(vector input)
    {
        for (vector::iterator i = input.begin(), end = input.end(); i != end; ++i)
        {
            try {
                TrimLeft(*i);
            } catch (...) {} /* BUGID 17839 */
        }
    }
    
  • 10-21-2012 3:50 PM In reply to

    Re: Make a subtle memory leak

    Oldie but goldie (in JS) :
    
    
     // init my shiny ajax page
     function initPage() {
    
      // setup event handlers
      $("#foobuttontop").click(function() { doFoo("top"); });
      $("#foobuttonbottom").click(function() { doFoo("bottom"); });
      // ...
    
      // all handlers are set up - and we're do- oh, wait, we'll still have to do some preprocessing involving this one really huge object...
      var hugeObject = createHugeObject();
      hugeObject.doPreprocessing();
    
      // alright. NOW we're really done. Good thing we just stored the huge object in a local variable so it can be GCed now...
     }
    
    
  • 10-22-2012 5:33 AM In reply to

    Re: Make a subtle memory leak

    PSWorx:
    Oldie but goldie (in JS) :
     

    Explain to the incompetent dummies how this is a memory leak.

    Because I don't see it.


    In complex analysis, a meromorphic function on an open subset D of the complex plane is a function that is holomorphic on all D except a set of isolated points

  • 10-22-2012 9:44 AM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,530

    Re: Make a subtle memory leak

    I guess some JS implementations reference the huge object in the closures of the event handlers.

    dhromed:

    PSWorx:
    Oldie but goldie (in JS) :
     

    Explain to the incompetent dummies how this is a memory leak.

    Because I don't see it.

     

     

    beanbag girl 4ever ... or maybe Astah girl?
  • 10-22-2012 9:55 AM In reply to

    Re: Make a subtle memory leak

    ammoQ:

    I guess some JS implementations reference the huge object in the closures of the event handlers.

    dhromed:

    PSWorx:
    Oldie but goldie (in JS) :
     

    Explain to the incompetent dummies how this is a memory leak.

    Because I don't see it.

     

     

    According to ECMAScript spec, all conforming implementations have to. This is so you can do stuff like
    
     function makeClosure() {
      var a = 5;
      return function(x) {
       eval(x); // no explicit reference to 'a' here ...
      };
     }
    
     var closure = makeClosure();
     closure("console.info(a)"); // ... still prints 5.
    


    ... that's not saying people haven't found some clever heuristics to work around that problem by today.
  • 10-22-2012 2:11 PM In reply to

    Re: Make a subtle memory leak

    The How-smart-is-my-garbage-collector test:

    class WidgetContainer;

    class Widget
    {
      private:
        int id;
        WidgetContainer *owner;

      public:
        Widget(int n, WidgetContainer *wc)
        {
          id = n;
          owner = wc
        }
    }

    class WidgetContainer
    {

      private:

        List<Widget> widgets;



      public:

        void add(Widget w)
        {
          widgets.add(w);
        }
    }



    void test()
    {
      WidgetContainer wc = new WidgetContainer();

      for (int i = 0; i < 1000000; i++) {
        wc.add(new Widget(i, &wc));
      }
    }

    I think most modern runtimes will figure this one out, but I'm not 100% positive on that.

  • 10-23-2012 8:57 AM In reply to

    Re: Make a subtle memory leak

    curtmack:
    I think most modern runtimes will figure this one out, but I'm not 100% positive on that.
    You mean the circular references? Isn't that the whole point of using garbage collectors and not reference counting?
  • 11-01-2012 4:49 PM In reply to

    Re: Make a subtle memory leak

    I choose VB.NET. Because it's on this machine.

    Public Class LeakEverything

    Public Event Generic()
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    For i As Integer = 0 To 10000
    Dim that As New Thing()
    AddHandler Me.Generic, AddressOf that.HandleGenericEvent
    Next
    GC.Collect()'Just to make sure...
    End Sub
    End Class

    Public Class Thing

    Private m_junk As Byte()
    Public Sub New()
    ReDim m_junk(1024)
    End Sub
    Public Sub HandleGenericEvent()
    'Do Nothing
    End Sub
    End Class

    It's more subtle if the byte array is removed, of course.

  • 11-28-2012 11:39 PM In reply to

    Re: Make a subtle memory leak

    PSWorx:
    According to ECMAScript spec, all conforming implementations have to. This is so you can do stuff like...<snip&rt;
    That's awesome and terrifying and and I don't even need to read the rest of the thread to vote that up as "best subtle memory leak". #slowclap
  • 11-29-2012 4:25 AM In reply to

    • PJH
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Newcastle, UK
    • Posts 3,910

    Re: Make a subtle memory leak

    savar:
    <snip&rt;
    What the fuck is that? "Right than"? There's a preview tab for a reason.
    "Because you watched 'The Very Hungry Caterpillar,' we recommend 'The Human Centipede.'"
    --
    UED - Countryside: To kill Piers Morgan
  • Parp!
  • 11-29-2012 5:48 AM In reply to

    Re: Make a subtle memory leak

    Ben L.:
    mott555:
    List<object> myList = new List<object>();
    for (int i = 0; i < int.MaxValue; i++)
        myList.Add(new object());
    In an ideal language, object would be a zero-width struct, which would make the last line of that increment length and do nothing else.

    Sorry, but you need to account for new object() != new object().

    The following lists are different:
    listA = new List();
    listA.Add(new object());
    listA.Add(new object());
    
    listB = new List();
    item = new object();
    listB.Add(item);
    listB.Add(item);
    
  • 12-10-2012 1:59 AM In reply to

    Re: Make a subtle memory leak

    savar:
    PSWorx:
    According to ECMAScript spec, all conforming implementations have to. This is so you can do stuff like...<snip&rt;
    That's awesome and terrifying and and I don't even need to read the rest of the thread to vote that up as "best subtle memory leak". #slowclap
    You don't have to use JS regularly, do you? :) Everyone that's ever written any large script in JS should know that all variable definitions are implicitly moved to the top of the enclosing function. If you don't, you don't know the basics of the language you're using and you've definitely never used JSLint.
  • 01-09-2013 4:56 PM In reply to

    Re: Make a subtle memory leak

    PSWorx:
    Oldie but goldie (in JS) :

     // init my shiny ajax page
     function initPage() {
    
      // setup event handlers
      $("#foobuttontop").click(function() { doFoo("top"); });
      $("#foobuttonbottom").click(function() { doFoo("bottom"); });
      // ...
    
      // all handlers are set up - and we're do- oh, wait, we'll still have to do some preprocessing involving this one really huge object...
      var hugeObject = createHugeObject();
      hugeObject.doPreprocessing();
    
      // alright. NOW we're really done. Good thing we just stored the huge object in a local variable so it can be GCed now...
     }
    
    I assume here the intention is that doFoo is a function local to initPage, otherwise this won't actually work in Firefox since if it can't find any uses of local variables in nested functions it won't bother saving the scope.

     

  • 03-01-2013 5:29 PM In reply to

    • ekolis
    • Top 100 Contributor
    • Joined on 01-09-2008
    • Cincinnati, OH, USA
    • Posts 600

    Re: Make a subtle memory leak

    for (i = int.MinValue; i <= int.MaxValue; i++)
    new byte[int.MaxValue];

    Nobody said I was good at subtlety.
    I'm Spark Mandrill, and I'll... hey... can I... what, it BOUNCES?... 'kay, I'm splodin' now.
  • 03-01-2013 6:52 PM In reply to

    • Ben L.
    • Top 10 Contributor
    • Joined on 12-22-2010
    • Inventor of the 186-hour work week
    • Posts 3,607

    Re: Make a subtle memory leak

    ekolis:
    for (i = int.MinValue; i <= int.MaxValue; i++)
    new byte[int.MaxValue];

    Nobody said I was good at subtlety.
    That doesn't leak any memory. It just makes a lot of garbage for the GC to pick up.
  • Morbs is the smartest!
  • 03-08-2013 4:38 PM In reply to

    Re: Make a subtle memory leak

    NeilRashbrook:
    PSWorx:

    Oldie but goldie (in JS):

     // init my shiny ajax page
     function initPage() {
    
      // setup event handlers
      $("#foobuttontop").click(function() { doFoo("top"); });
      $("#foobuttonbottom").click(function() { doFoo("bottom"); });
      // ...
    
      // all handlers are set up - and we're do- oh, wait, we'll still have to do some preprocessing involving this one really huge object...
      var hugeObject = createHugeObject();
      hugeObject.doPreprocessing();
    
      // alright. NOW we're really done. Good thing we just stored the huge object in a local variable so it can be GCed now...
     }
    

    I assume here the intention is that doFoo is a function local to initPage, otherwise this won't actually work in Firefox since if it can't find any uses of local variables in nested functions it won't bother saving the scope.

    Indeed. You'd need to have something that directly or indirectly equates to using eval in the scope of initPage for that scope to qualify to 'always' be retained, e.g., eval itself or the string based versions of setTimout and setInterval.

  • 03-11-2013 12:10 AM In reply to

    • ekolis
    • Top 100 Contributor
    • Joined on 01-09-2008
    • Cincinnati, OH, USA
    • Posts 600

    Re: Make a subtle memory leak

    English:

    (Enter a memory leak, stage right.)

    MEMORY LEAK: Ahem! Good sirs, I do beg your pardon, but I will be absconding with some of your memory.

    (MEMORY LEAK absconds with 4 GIGABYTES of RAM)

    CHORUS: O where is our RAM? O where is our RAM? O where O where O where O where O where... is our poor RAM?
    I'm Spark Mandrill, and I'll... hey... can I... what, it BOUNCES?... 'kay, I'm splodin' now.
  • 05-30-2013 8:37 AM In reply to

    • dkf
    • Top 50 Contributor
    • Joined on 04-24-2008
    • Manchester, UK
    • Posts 1,138

    Re: Make a subtle memory leak

    Nothing quite beats the power of memory leaks driven by string interning deep inside a library.
  • 05-30-2013 10:55 AM In reply to

    Re: Make a subtle memory leak

    ekolis:
    English:


    CHORUS: O where is our RAM? O where is our RAM? O where O where O where O where O where... is our poor RAM?

    Rammy, Rammy, Rammy Ram -- and it went, wherever I, Did Go....

    I > U
  • 06-05-2013 5:38 AM In reply to

    Re: Make a subtle memory leak

    Ben L.:
    Your choice of language. Go.
     

    That's not much of a choice.

    Begging the question since 2007.
  • 06-05-2013 5:42 AM In reply to

    Re: Make a subtle memory leak

    dkf:
    Nothing quite beats the power of memory leaks driven by string interning deep inside a library.
     

    That is so hot.


    In complex analysis, a meromorphic function on an open subset D of the complex plane is a function that is holomorphic on all D except a set of isolated points

  • 06-05-2013 12:18 PM In reply to

    Re: Make a subtle memory leak

    dhromed:

    dkf:
    Nothing quite beats the power of memory leaks driven by string interning deep inside a library.
     

    That is so hot.

    What could be dirty about interning your string deep inside a library until it leaks?
    Signatures are stupid.
  • 06-06-2013 7:42 PM In reply to

    Re: Make a subtle memory leak

    She gonna tell me too. Hey, look at me when... You know how you can tell who the arch-villain's going to make more shows. She gonna shoot you in the head then and the finder of lost children. And I will strike down upon thee with a blank expression on his face sitting outside on a mechanical helicopter that shakes when... You know how you can tell me too.
  • 06-07-2013 5:31 AM In reply to

    Re: Make a subtle memory leak

    Maciejasjmj:
     

    Nobody's been able to find it for years, so that must mean it's pretty subtle.


    In complex analysis, a meromorphic function on an open subset D of the complex plane is a function that is holomorphic on all D except a set of isolated points

Page 1 of 1 (28 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems