Skip to content

memory leak with SPI() or new SPI() #1923

Closed
@fanoush

Description

@fanoush

as per forum topic http://forum.espruino.com/conversations/348343/#15490345
it looks like when creating software SPI or I2C or Serial there is a memory leak when deleting it

>var s=SPI();process.memory().free
=2575
>for(var i=0;i<2000;i++)s=SPI();process.memory().free
=570

it is same with s=SPI() or s=new SPI() while both do something slightly different, the leak is in both.

I guess I don't fully understand difference between var t=new Type() vs var t=Type(), seems to often do same thing e.g. d=Date(), d=new Date() both creates date however with SPI() it seems different

>
>var s=new SPI()
=SPI: {  }
>s
=SPI: {  }
>var s=SPI()
=undefined
>s
=undefined
>

Also what is maybe related that there is

>global.SPI
=function () { [native code] }

so with s=SPI() this method is called while new SPI() creates new instance of SPI object, pretty confusing :-)
What is also strange and may be related to the leak is that after var s=new SPI() there are two objects in global named SPI as autocomplete shows and it can be deleted once. See
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions