[petsc-users] Mat Destroy

Matthew Knepley knepley at gmail.com
Sun Aug 25 07:41:48 CDT 2013


On Sun, Aug 25, 2013 at 7:38 AM, Michael Povolotskyi <mpovolot at purdue.edu>wrote:

> On 8/23/2013 7:37 PM, Jed Brown wrote:
>
>> Barry Smith <bsmith at mcs.anl.gov> writes:
>>
>>>     We call free() at that point. But not that in Unix this does not
>>>     mean the memory is returned to the operating system so you will not
>>>     see the process memory go down.  If you then allocate new objects
>>>     they will reuse this memory.
>>>
>> Also note that MatDestroy only releases a references, so if another
>> object still holds a reference to your matrix, nothing will be freed.
>>
> Thank you!
> Just to clarify: if a code reads like this:
>
> Mat A;
> MatCreate(MPI_COMM_WORLD, &A);
>
> Mat B = A;
> ....
> MatDestroy(&B);
>
> Will the free() function be called for the memory that contains the matrix
> data in this case?
>

Yes, it will. You might want

Mat B = A;
PetscObjectReference((PetscObject) B);

so that you also need

MatDestroy(B);

    Matt


> Thank you,
> Michael.
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130825/e3b721c3/attachment.html>


More information about the petsc-users mailing list