rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.91k stars 299 forks source link

Holy RAM, batman! (Out of memory errors and excessively high memory usage) #3347

Open bclothier opened 7 years ago

bclothier commented 7 years ago

After observing random "System resources exceeded" or "Out of memory" with my usercode which didn't quite make sense, I later ran quick fixes. After applying changes, I went to start the application and immediately got the System resources exceeded *despite have NOT run any VBA code`.

Suspicious, I restarted Access, then opened Access. Noted the working set memory at 8MB. Launch open VBA, the working set rockets to 175MB working set memory. Run parse, the working set goes up to 300 MB! Open quick inspector, and refresh, the working set climbs to 475 MB!

I might be going out on a limb but it sure looks like to me something's hemorrhaging hemorrhages.

bclothier commented 2 years ago

That is totally unexpected. However, I'd also add that we should also revert the files as to prove that the memory errors re-appear and thus is not a fluke that was just coincidental to you running the LAA tool.

hecon5 commented 2 years ago

To confirm, you want me to revert the files (even though the tool didn't do anything)? Revert to not LAA, or just reinstall RD?

bclothier commented 2 years ago

Either would work, yes. If it was really the LAA tool (even though it reported it did nothing) then reverting should bring back the memory errors and re-running it should then make it go away again, which would be more stronger proof that there's something afoot with the LAA thingee.

hecon5 commented 2 years ago

Alright, I'll give this a go and let you know; one moment, digs around in computer for files

hecon5 commented 2 years ago

Alright. I did it. Was not able to change the flag; got a write error, in fact.

  1. I unloaded and ran the tool to clear the value.
  2. Restarted Access. RD ran slower and parsing took a while, and memory stayed around the 1GB mark. I was not able to induce the memory error, but the memory in use stayed below 1GB; but I did notice a performance degradation.
  3. Closed Access, ran the tool to set LAA flag.
  4. Indicated no change (again).
  5. Started Access, RD parses faster.

I cannot explain it. But, it clearly did something. RD info: Version 2.5.2.5994 OS: Microsoft Windows NT 10.0.19042.0, x64 Host Product: Microsoft Office x64 Host Version: 16.0.14729.20260 Host Executable: MSACCESS.EXE

Immediate Window output

Note: "rddllfile" is a string constant I set to C:\Users\USERNAME\AppData\Local\Rubberduck\Rubberduck.dll to make it easier to use immediate window.

SetLaaFlag rddllfile,DisplayLaaStatusOnly
LAA is enabled.

SetLaaFlag rddllfile,TurnOffLaa
LAA is enabled.
Switching OFF LAA
(Failed error write to file)
SetLaaFlag rddllfile,TurnOnLaa
LAA is enabled.
Doing nothing
bclothier commented 2 years ago

Mind linking to the LAA tool you're using?

hecon5 commented 2 years ago

Sure thing! I ran this via Excel (because you can't run this in the same Application you're trying to set), if that helps any.

Direct link to DL: modLargeAddressAware.zip Page source: The /LARGEADDRESSAWARE (LAA) flag demystified

bclothier commented 2 years ago

Thanks, reading the source code, it makes less sense because it really does nothing beyond reading the LAA flag from the file. I had surmised that maybe it was reporting "doing nothing" but in actuality doing something. That doesn't seems to be the case, so I'm not able to explain why just running the LAA tool affects it so. If it was simply because the LAA tool was reading the flag, then clearing the value (and failing) should have not have made it run slower again.

hecon5 commented 2 years ago

I agree, I am also flummoxed. But in my anecdotal test size of 1, it seemed to work.

I'll keep an eye on memory use for a bit and see if anything changes, but, other than my machine was placebo satisfied, I've got nothing.

Tragen commented 2 years ago

Try editbin from Visual Studio, I use this to set the flags on my software. And compare the files between before and after editing it.

A9G-Data-Droid commented 2 years ago

I used dumpbin.exe to check for the LAA flag on all DLL files in the RD directory. Then I listed only those not LAA aware to get a shorter list.

Here is what I get:

EasyHook32.dll is NOT LAA aware
EasyLoad32.dll is NOT LAA aware
ICSharpCode.AvalonEdit.dll is NOT LAA aware
Microsoft.Expression.Interactions.dll is NOT LAA aware
office.dll is NOT LAA aware
stdole.dll is NOT LAA aware
System.Windows.Interactivity.dll is NOT LAA aware

NOTE: All the main RD DLL files appear to have the LAA flag set already.

Here is the full header for the main DLL in question:

Dump of file Rubberduck.dll

PE signature found

File Type: DLL

FILE HEADER VALUES
             14C machine (x86)
               3 number of sections
        8A85333F time date stamp
               0 file pointer to symbol table
               0 number of symbols
              E0 size of optional header
            2022 characteristics
                   Executable
                   Application can handle large (>2GB) addresses
                   DLL

OPTIONAL HEADER VALUES
             10B magic # (PE32)
           48.00 linker version
           17200 size of code
             600 size of initialized data
               0 size of uninitialized data
           190A2 entry point (100190A2)
            2000 base of code
           1A000 base of data
        10000000 image base (10000000 to 1001DFFF)
            2000 section alignment
             200 file alignment
            4.00 operating system version
            0.00 image version
            6.00 subsystem version
               0 Win32 version
           1E000 size of image
             200 size of headers
               0 checksum
               3 subsystem (Windows CUI)
            8560 DLL characteristics
                   High Entropy Virtual Addresses
                   Dynamic base
                   NX compatible
                   No structured exception handler
                   Terminal Server Aware
          100000 size of stack reserve
            1000 size of stack commit
          100000 size of heap reserve
            1000 size of heap commit
               0 loader flags
              10 number of directories
               0 [       0] RVA [size] of Export Directory
           19050 [      4F] RVA [size] of Import Directory
           1A000 [     3B8] RVA [size] of Resource Directory
               0 [       0] RVA [size] of Exception Directory
               0 [       0] RVA [size] of Certificates Directory
           1C000 [       C] RVA [size] of Base Relocation Directory
           19034 [      1C] RVA [size] of Debug Directory
               0 [       0] RVA [size] of Architecture Directory
               0 [       0] RVA [size] of Global Pointer Directory
               0 [       0] RVA [size] of Thread Storage Directory
               0 [       0] RVA [size] of Load Configuration Directory
               0 [       0] RVA [size] of Bound Import Directory
            2000 [       8] RVA [size] of Import Address Table Directory
               0 [       0] RVA [size] of Delay Import Directory
            2008 [      48] RVA [size] of COM Descriptor Directory
               0 [       0] RVA [size] of Reserved Directory

SECTION HEADER #1
   .text name
   170A8 virtual size
    2000 virtual address (10002000 to 100190A7)
   17200 size of raw data
     200 file pointer to raw data (00000200 to 000173FF)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
60000020 flags
         Code
         Execute Read

  Debug Directories

        Time Type        Size      RVA  Pointer
    -------- ------- -------- -------- --------
    00000000 repro          0 00000000        0

SECTION HEADER #2
   .rsrc name
     3B8 virtual size
   1A000 virtual address (1001A000 to 1001A3B7)
     400 size of raw data
   17400 file pointer to raw data (00017400 to 000177FF)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         Read Only

SECTION HEADER #3
  .reloc name
       C virtual size
   1C000 virtual address (1001C000 to 1001C00B)
     200 size of raw data
   17800 file pointer to raw data (00017800 to 000179FF)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
42000040 flags
         Initialized Data
         Discardable
         Read Only

  Summary

        2000 .reloc
        2000 .rsrc
       18000 .text
bclothier commented 2 years ago

As a FYI - I did the same thing and it did not make any difference in the performance.

hecon5 commented 2 years ago

I mean, I expect nearly no one else will have the same experience. I personally figured it would be another road to nowhere. But, if it was a fluke or not,... I swear it did do something. I haven't had an out of memory error since I did, and I was getting them left and right.

A9G-Data-Droid commented 2 years ago

I think the host has to be LAA aware. All office apps are except Access, which is supposed to get LAA this September. If you have patched your MSACCESS.EXE then it would load all extensions as LAA, ready or not.

hecon5 commented 2 years ago

That's what I thought, except 64bit MSACCESS.EXE IS LAA already, and I was getting out of memory errors around 1GB in size. It's ... flummoxing to be sure.