Strange MemoryLeak Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Airslash
    New Member
    • Nov 2007
    • 221

    Strange MemoryLeak Issue

    Hello,

    I hope this falls under the correct topic...

    We have a small application that uses the COM ports on a system to communicate with external devices. This application is written in Delphi and makes use of some third-party components.

    We have around 500 identical systems, sort of speak, and there's only one location where this application is getting memoryleaks up to 500mb.
    All other locations are running fine and don't suffer from this problem.

    I'm more inclined to believe this to be a Windows problem on that system then a fault in the application. Anyone who can shed some insight on this, or experienced a similar issue?
  • Jyoti Ballabh
    Banned
    New Member
    • Jul 2010
    • 115

    #2
    In most Delphi applications, where you use the components you drop on a form, you do not need to care to much about memory management. Once the component is placed on a form, the form becomes its owner and will free the memory taken by the component once the form is closed. Form, as the owner, is responsible for memory deallocation of the components it hosted. In short: components on a form are created and destroyed automatically. Now, when you need to use the TDeveloper class, you create an instance of the class by calling the Create method (constructor). The Create method allocates memory for a new object and returns a reference to the object.

    var
    zarko : TDeveloper
    begin
    zarko := TMyObject.Creat e;
    zarko.DoProgram ;
    end;

    This is a simple memory leak

    Comment

    • Jyoti Ballabh
      Banned
      New Member
      • Jul 2010
      • 115

      #3
      Whenever you create an object, you must dispose the memory it occupied. To free the memory an object allocated, you must call the Free method. To be perfectly sure, you should also use the try / finally block:

      var
      zarko : TDeveloper
      begin
      zarko := TMyObject.Creat e;
      try
      zarko.DoProgram ;
      finally
      zarko.Free;
      end;
      end;

      This is an example of a safe memory allocation and deallocation code.

      Warning: If you want to dynamically instantiate a Delphi component and explicitly free it sometime later, always pass nil as the owner. Failure to do so can introduce unnecessary risk, as well as performance and code maintenance problems.

      Comment

      • Airslash
        New Member
        • Nov 2007
        • 221

        #4
        I know what might cause a memory leak in Delphi.
        I'm more interested as to why the memory leak only occurs on one specific system and not the 245 other systems we have running.

        And they're all running the same OS, have the same hardware and run the same version of the software written.

        Comment

        • Jyoti Ballabh
          Banned
          New Member
          • Jul 2010
          • 115

          #5
          I'll get back to you later on this one. An isolated instance of system memory leak. I can think of either malware of defect in Assembly Coding. I have never encountered or tackled this problem before.

          Comment

          • Airslash
            New Member
            • Nov 2007
            • 221

            #6
            aye,

            it's a first one for me as well.
            Normally if it's a coding memoryleak I expect it to appear in all the applications on all the systems, but it's really just this one.

            Comment

            • Jyoti Ballabh
              Banned
              New Member
              • Jul 2010
              • 115

              #7
              that's what got me thinking, if it's a coding error or let's say something to do with the OS, the problem should persist in all the systems; why just one? I will have to rule out any mechanical damage or should I?

              Comment

              • Airslash
                New Member
                • Nov 2007
                • 221

                #8
                I doubt mechanical damage to the components would be the cause. I'd expect the application or even the system to simply crash if the memory got damaged.

                Any suggestions on a good diagnostics tool to check RAM and system performance?

                Comment

                • Jyoti Ballabh
                  Banned
                  New Member
                  • Jul 2010
                  • 115

                  #9
                  I don't know, I do it the old fashioned way if I have to. Run through the Windows memory diagnostic executable file, mtinst.exe..... . i can give you the details on this one if you want.

                  Comment

                  • Jyoti Ballabh
                    Banned
                    New Member
                    • Jul 2010
                    • 115

                    #10
                    For some hardware configurations, Windows Memory Diagnostic can identify the specific failing memory component. If Windows Memory Diagnostic can successfully isolate all the errors detected to one or more corresponding memory modules, the View errors by memory module option will be available in the menu. You can use this option to determine which specific memory modules are failing and need to be removed or replaced. This could be one of the causes of the memory leaks. I am not entirely sure, though.

                    Comment

                    • Airslash
                      New Member
                      • Nov 2007
                      • 221

                      #11
                      I'll take a look at it.

                      Comment

                      • Oralloy
                        Recognized Expert Contributor
                        • Jun 2010
                        • 988

                        #12
                        Just as an observation, the easiest fix might be to re-build the failing system.

                        Either re-install your stock image (assuming you have one), or start with a Windoze disk and re-install all the necessary software.

                        Comment

                        • Airslash
                          New Member
                          • Nov 2007
                          • 221

                          #13
                          not an option i'm afraid.
                          This is a live production system at the client and cannot be simply taken down.

                          Comment

                          • Oralloy
                            Recognized Expert Contributor
                            • Jun 2010
                            • 988

                            #14
                            Unfortunate. It's probably cost everyone more time to "fix" the problem at this point than a rebuild will take.

                            Sorry, I've been caught where you are, too. There are no pretty answers.

                            Please let us know what the resolution is, when you find it.

                            Good Luck!

                            Comment

                            • Airslash
                              New Member
                              • Nov 2007
                              • 221

                              #15
                              will definitly keep you updated on our "adventure" .

                              Tommorow we're spitting through all the log files we have been generating from perfmon and see if we can find anything.

                              Comment

                              Working...