Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
When I call malloc to allocate memory for a pointer which is local to a function ....
When I call malloc to allocate memory for a pointer which is local to a function, do I have to explicitly free it?
✍: Guest
Yes. Remember that a pointer is different from what it points to. Local variablesare deallocated when the function returns, but in the case of a pointer variable, this means that the pointer is deallocated, not what it points to. Memory allocated with malloc always persists until you explicitly free it. (If the only pointer to a block of malloc'ed memory is a local pointer, and if that pointer disappears, there will be no way to free that block.) In general, for every call to malloc, there should be a corresponding call to free.
2016-03-31, 1741👍, 0💬
Popular Posts:
How To Return Top 5 Rows? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqueries If you want ...
What are unadjusted function points and how is it calculated? Unadjusted function points = ILF + EIF...
How To Divide Query Output into Groups? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY You...
What is CMM and different levels? explain? The Capability Maturity Model (CMM) is a process capabili...
How To Assign Debug Privileges to a User? - Oracle DBA FAQ - Introduction to Oracle SQL Developer In...