I have some question on the memory management in XPCOM.

In idl, there are the following cases, please tell me whether my understanding is right.

1. wstring and string as parameter to a XPCOM call.
In this case, it is the caller's responsibility to manage the memory of this wstring or string. The callee will only read from the wstring or string, and will not free it. Since the memory is allocated/deallocated all by caller, so caller can choose any method to allocate/deallocate the memory.

2. wstring and string as return value. For example, as "out" parameter or as attribute.
In this case, the caller is responsible to use the nsIMemory to release the memory associated with the wstring or string.

3. nsAString and nsACString as parameter to a XPCOM call.
In this case, the caller should manage to allocate and deallocate the nsAString or nsACString.

4. nsAString and nsACString as attribute or as "out" parameter.
In this case, it is still the caller's responsibility to first allocate a nsAString or nsACString (empty content), and then pass this to the XPCOM call. In side the call, the callee may change the content of the nsAString or nsACString. Then after the return of this method, it is still the caller's responsiblity to deallocate the memory for the nsAString or nsACString. (does this mean that both the caller and callee must use the nsIMemory to manage the memory used by the nsAString?)


Thanks in advance.

jml


Reply via email to