« Previous Next »

Answered Thread: Edit: Must all config object be Released & local static variables question

Last post 10-12-2009 10:51 PM by DF_Frederic. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 10-07-2009, 12:50 AM

    Edit: Must all config object be Released & local static variables question

    Edit: I decided to add another question since they're both related to the config retrieval in a way and didn't want to open another thread for it.

     

    They may be a simple questions but it comes from the fact that my background is not C++.

     

    First question:

    IIS7 modules can allocate memory that can be managed by IIS itself.  For the administration section, it seems that every object you request, like for example a  IAppHostProperty, must be released after using it. The MSDN sample shows it but the documentation doesn't state it directly (maybe because the object derive from IUnknown).

     

    Some of the code path in our application code exit before releasing the object(s).  My guess is that it will create a memory leak.  Is my reasoning correct?

     

    Second question:

    When retrieving part of the configuration, you must use a VARIANT struct.  A helper function for reading specific part of the configuration was made.  Inside this function, I found a static VARIANT.  This static VARIANT is returned with the content of the value requested on each call.

    All I can read is usually static inside function is non thread safe and it concerns me. I'm no MT expert but since I guess every request for the module must be running in it's own thread, maybe there is no threading issue or am I wrong?

     

    Thank you in advance for any information on the subject.

  • 10-09-2009, 12:51 AM In reply to

    Re: Edit: Must all config object be Released & local static variables question

    Regarding the static variable issue, I did some test and was able to figure out the answer: the static variable is seen in both request and this is bad. This mean if one modify the content while the other access it, the final result would be unpredictable.  I had a feeling it would be that but was hoping it was not the case.  I will fix the code to remove any static used.

     

    The first question is still pending. I'm almost sure the answer will be "Yes, you must release all objects even thought the admin object came from IIS 7, it's a COM thing" but I just want to confirm since only the examples shows that you must release them but nothing is said explicitly in the documentation. Since a few examples have mistakes here and there, I would like to confirm this part.

     

    Thanks again in advance for any information confirming this behavior.

     

     

  • 10-12-2009, 10:03 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Answered Re: Edit: Must all config object be Released & local static variables question

    You are correct - you must follow the memory management rule for whatever API you are using.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 10-12-2009, 10:51 PM In reply to

    Re: Edit: Must all config object be Released & local static variables question

     Thanks again Anil for your answer. Now it's time to re-factor the affected code.

Page 1 of 1 (4 items)
Microsoft Communities