pycpython
pycpython

Reputation: 17

Python: Does array creation automatically allocate memory?

When using large arrays, does python allocate memory as default, unlike C for example?

More specifically, when using the command array=[1,2,3], should I worry about freeing this and every other array I create?

Looking for answers on the web just confused me more.

Upvotes: 0

Views: 667

Answers (1)

Reblochon Masque
Reblochon Masque

Reputation: 36712

array=[1,2,3] is a list, not an array. It is dynamically allocated (resizes automatically), and you do not have to free up memory.

The same applies to arrays from the array module in the standard library, and arrays from the numpy library.

As a rule, python handles memory allocation and memory freeing for all its objects; to, maybe, the exception of some objects created using cython, or directly calling c modules.

Upvotes: 1

Related Questions