Best. Memory. Leak. Ever.



  • If you've ever used Microsoft's Excel API (if you can call it that), you'll notice that every time you instantiate an Excel.Application object, it'll actually spawn a new copy of Excel.exe.  A system we use had the unfortunate need to pull some data out of an Excel spreadsheet via this API - it would open a file via API, grab some cells, make some changes, and close it again.  All in "Shared Workspace" mode (which is why it used the API instead of opening the xls manually).

    Unfortunately, every now and then it'll encounter an unexpected value in one of the cells (i.e. someone was editing it), and then travel down a rarely-used codepath which causes the process to terminate before calling Application.Quit().  Which, of course, leaves the copy of Excel.exe in memory.

    In other words,  the extract process isn't just leaking memory, it's leaking entire copies of Excel.  In fact, on the machine it's running on, I count about 30 copies of Excel.exe, each happily taking up 15mb of ram and 1% cpu, doing absolutely nothing.  I dunno if this is a Microsoft WTF, or the person who wrote the extract WTF, or what, but it sure is strange (and is driving me nuts).

    WTF! 



  • 15MB of nothing is hardly the worst memory leak ever, considering that Eclipse is using 210MB on my machine at the moment....

    My Company Branded (and no doubt monitored) AIM client is using about 70 right now too.  Sheesh.




  • 15MB of nothing is hardly the worst memory leak ever, considering that Eclipse is using 210MB on my machine at the moment....

    My Company Branded (and no doubt monitored) AIM client is using about 70 right now too.  Sheesh.

     

    firefox memory usage



  • I'd say its the programmers WTF any way you put it. The program should be careful to clean up any instances of Excel that it opens. Since it goes down a rarely used codepath, than that path should be tested more stenuously, and it sounds weird that it would result in killing the application. I'd say they need more error and exception checking in that code path. But either way you put it, if the program opens up an instance of Excel, it should clean it up. Also, it might make more sense to open it up in a way that the user can't edit it. I'm not an expert on this stuff, but I'm sure there is an easy trick to it by specifying how you want it to open. It should be programming 101 to clean up its own resources. It is in vein to try to compensate for poor programming practices.



  • Why on Earth does the API need to open Excel.exe to grab data out of a spreadsheet?  Doesn't Microsoft know how to parse their own file formats???

     

    There is probably an XLS reader/write module for the majority of widely used languages.  At my former job, I wrote a command-line PHP script that grabbed data out of an XLS spreadsheet and converted it into a format suitable for importing into another system.  And yes, I realize PHP is a bit of a WTF choice to develop that script for, but there was already a PHP interpreter installed on that computer.  But, my point was that the old XLS file format can't be that big of a mystery if there is even a PHP module that can parse them.  Unless there is something I'm missing, this seems like a big WTF on Microsoft's part.



  • @bighusker said:

    Why on Earth does the API need to open Excel.exe to grab data out of a spreadsheet? Doesn't Microsoft know how to parse their own file formats?

    What happens if the API is for excel 4, but the user has excel 2007? Obviously the correct solution is to open excel.



  • @bighusker said:

    Why on Earth does the API need to open Excel.exe to grab data out of a spreadsheet?  Doesn't Microsoft know how to parse their own file formats???

     

    There is probably an XLS reader/write module for the majority of widely used languages.  At my former job, I wrote a command-line PHP script that grabbed data out of an XLS spreadsheet and converted it into a format suitable for importing into another system.  And yes, I realize PHP is a bit of a WTF choice to develop that script for, but there was already a PHP interpreter installed on that computer.  But, my point was that the old XLS file format can't be that big of a mystery if there is even a PHP module that can parse them.  Unless there is something I'm missing, this seems like a big WTF on Microsoft's part.

    The API is a lot more involved than you seem to think. It is usually something like VBScript or VB6 grabbing an Excel COM object. It is not just a file parser. If you use the COM object like this, it opens an instance (can be windowless if chosen) and it allows you to basic 'remote control' Excel through the interface.

     



  • @pitchingchris

     No, it's the way the API works. It has to do with OLE, etc.  I've had .NET apps that I've been debugging which were standalone and would launch Excel as part of the system through the exposed API, then my buggy program would throw an unexpected exception and revert to the debugger.  Well, just because you have to quit using the program doesn't mean it'll call your quit routine, so even though the encapsulation was there to close Excel, it never ran that portion of the code.  Thus, Excel.exe would be happily running in the background.

     Nothing to be done except not have buggy code.



  • @Lingerance said:

    @bighusker said:
    Why on Earth does the API need to open Excel.exe to grab data out of a spreadsheet? Doesn't Microsoft know how to parse their own file formats?
    What happens if the API is for excel 4, but the user has excel 2007? Obviously the correct solution is to open excel.
    Thus the magic of the registry reveals itself.  The version to be used is the part that is registered under Excel so that when the API needs to open Excel, it get's the right path.  That's why the installer file is so necessary, not because it can unpack a zip to a directory, but because it attempts to make sure the right registry keys are manipulated.



  • Eclipse is pretty decent. It runs on about 170 megs on my machine and i got 2 gigs (yay good dev computers).

    Eclipse + Flex Builder 3 runs at least 400 megs. And I seriously think that there are memory leaks. 



  • @dlikhten said:

    Eclipse is pretty decent. It runs on about 170 megs on my machine and i got 2 gigs (yay good dev computers).

    Eclipse + Flex Builder 3 runs at least 400 megs. And I seriously think that there are memory leaks. 

    High memory usage != Memory leaks.



  • try

    {

    DoStuffWithExcelAPI

    }

    catch (Exceptions)

    {

    OhNoes.Stuffbroke(); 

    }

    finally()

    {

    ExcelApiComObject.Dispose(); 

    }

     

    There, I fixed it for you. 



  • @Jonathan Holland said:

    There, I fixed it for you. 

    That's really not helpful.  I'm just trying to comment on the craziness of a system which leaks entire processes.

    Honestly, dontcha think I'd have thought of adding a finally block?



  • @Albatross said:

    @Jonathan Holland said:

    There, I fixed it for you. 

    That's really not helpful.  I'm just trying to comment on the craziness of a system which leaks entire processes.

    Honestly, dontcha think I'd have thought of adding a finally block?

    Another thing to reduce opening multiple copies is to use GetActiveObject to try to reference one that's already running (if there is one) and only creating the new instance if GetActiveObject fails.  The object is still reference counted, so you could still end up with a zombie excel, but you at least only have one to kill, rather than a whole flock of them. 



  • @Albatross said:

    @Jonathan Holland said:

    There, I fixed it for you. 

    That's really not helpful.  I'm just trying to comment on the craziness of a system which leaks entire processes.

    Honestly, dontcha think I'd have thought of adding a finally block?

     The real WTF is that you don't get sarcasm.
     



  • Here's a pretty good memory leak I had a while back:

    Fireox 1+ gig memory use 



  • @someonestolemyname said:

    Here's a pretty good memory leak I had a while back:

    <Image snipped>
     

    Of course, the Real WTF(tm) in that image is using 5MB for a screenshot utility when Windows has Alt+PrtSc built in...
     



  • @mallard said:

    Of course, the Real WTF(tm) in that image is using 5MB for a screenshot utility when Windows has Alt+PrtSc built in...
     

    So what program do you use to save the image on the clipboard, AND uses less than 5MB?

    The real WTF is not comparing like-for-like... 



  • My system is also leaking memory.

    I had someone look at it, he said something about fitting RAM modules the proper way and not leaving the case open around polish people.



  • @Otterdam said:

    @mallard said:

    Of course, the Real WTF(tm) in that image is using 5MB for a screenshot utility when Windows has Alt+PrtSc built in...
     

    So what program do you use to save the image on the clipboard, AND uses less than 5MB?

    The real WTF is not comparing like-for-like... 

    Um, they were comparing like-for-like.



  •  @PJH said:

    @Otterdam said:

    @mallard said:

    Of course, the Real WTF(tm) in that image is using 5MB for a screenshot utility when Windows has Alt+PrtSc built in...
     

    So what program do you use to save the image on the clipboard, AND uses less than 5MB?

    The real WTF is not comparing like-for-like... 

    Um, they were comparing like-for-like.
    No. If you use Alt+Print Scrn, you then need to open up paint or something to save it. Does Paint use less or more than 5 MB? (I'm assuming you can't simply paste a Print Screen in explorer; I've never tried.)



  • I use a screengrabber utility (2, in fact), to grab shots from games (instant save means multiple shots per game session) and, from paletted fullscreen modes (because fuck you just can't properly paste an external paletted image into photoshop).

    They are Screenshot Pilot and Fraps, for the interested.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.