Massive memory leaks and slowdowns in IDEs caused by __repr__
unbornchikken opened this issue · comments
As docs says: http://arrayfire.org/docs/group__print__func__tostring.htm#ga01f32ef2420b5d4592c6e4b4964b863b
User gotta free the returned function. In array
's __repr__
this won't happen, so it leaks by a huge margin, depending on the size of the array.
The other problem is __repr__
is gonna be called by IDEs like PyCharm to represent our array. If the array is big, its representation will be big and of course very slow to make. That makes PyCharm debugger kinda useless hog if I have some arrays in the scope.
My suggestion:
- Make
__repr__
a very lightweight method, showing only the type and dims of the array - Add
__str__
with the current implementation of__repr__
(gonna be slow on large arrays, but won't get triggered automatically) - Fix leaks
- (Leave
display
as is, it's good for a quick array representaion)
If you agree, I can make a PR of this.
@unbornchikken About __repr__
only printing the dims, this was what we were doing earlier before af_array_to_string
was a thing. May be add a comment asking them to use print or display to see the full array ?
Other than that the rest are welcome changes