CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Posts
    21

    Calling destructor with kill command

    Hi everybody,

    I have to work on a big application. This application consists in several processes.

    The processes are launched with a batch file (START command).
    When the administrator wants to stop the application, another batch file is launched. It contains KILL commands :
    KILL process1
    KILL process2
    and so on.

    It seems that the destructor of each application is not called.

    Can someone confirm that last point ? If so, how can I do to detect the end of an application ?

    Thanks.



  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Calling destructor with kill command

    A normal kill sends a message to the process - in Windows it is a WM_QUIT message, in console programming it is a signal SIGTERM.

    Windows will normally handle the WM_QUIT message, but a SIGTERM has no standard handler and you have to write one.

    Actually, I once implemented it by getting the SIGTERM to throw an exception! The main execution caught it because I did try..catch for this exception in main.

    A hard kill (-9 in UNIX, or shutting down via Task Manager in NT when it is "not responding") will not send the application a message at all but will shut it down and no code, destructors or otherwise, will be called.


    The best things come to those who rate

  3. #3
    Join Date
    Mar 2000
    Posts
    21

    A question about memory leak

    Thanks for your reply.

    I have another question then. If the application allocates memory during execution, can I suppose that Windows will free automatically the objects allocated when the application will be killed ? If so, I don't have to worry about memory leak problems.

    Thanks again.


  4. #4
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: A question about memory leak

    Heap memory is allocated by the heap manager, per-process. When your program shuts down, this memory will be freed automatically (on any operating system, as long as that operating system doesn't have bugs).

    I don't know what happens about memory allocated with GlobAlloc (on Windows).


    The best things come to those who rate

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured