How does compiler allocates memory to an object of a class which consists of list type variables which will expand with time when program is executing? Also, how does compiler ensure that required amount of memory is available as and when required and prevent memory leaks?
Asked
Active
Viewed 38 times
0
-
4The compiler is not responsible for making or managing dynamic allocations. – kaylum Mar 04 '20 at 10:40
-
Note that list nodes are not stored directly in the list object itself. A list typically stores just a pointer to the first list element. – Daniel Langr Mar 04 '20 at 11:18
-
Now, if we want to make a deep copy of the object and for that we allocate memory to the new object of the class using "new", then Will the memory allocated will have pointer to the list in the new variable? Because this will create a problem if we free the former object of the class. – Tarang Jain Mar 05 '20 at 08:01
-
Not clear what you are asking. If you make a deep copy then the new object does not reference the old object. – kaylum Mar 05 '20 at 09:25
1 Answers
0
Compiler doesn't allocate memory to list. Compiler only needs to know the data type of the list. For more info read this https://stackoverflow.com/a/58960527/2786098