Re: [SailfishDevel] QML arrays and memory leak

2015-06-10 Thread Kim Foder
Thanks for all your comments on this problem.

I have been using these last couple of months testing many different 
solutions, also those proposed here, but none have worked!

Now I have solved the problem by using an circular buffer instead of an array, 
so when I add a value I just changes the value at the current end of the 
buffer, and moves the end pointer to the next element, if the end pointer 
equals the start pointer that one is moved forward one place.

That's it, no more memory leak, at least none I have detected yet ;)

/Kim
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] QML arrays and memory leak

2015-05-05 Thread Tomasz Sterna
Dnia 2015-05-04, pon o godzinie 22:20 +0200, Kim Foder pisze:
 This works great, but it leaks memory fast, and after some time
 (between 1  2 hours) the OS kills all running apps!
 Any ideas how I can solve this?

Possibly you are creating/destroying values so fast, that GC does not
have time to kick in. Maybe try calling QJSEngine::collectGarbage() [1]
manually every few iterations. (QQmlEngine subclasses QJSEngine)

[1] http://doc.qt.io/qt-5/qjsengine.html#collectGarbage

-- 
 /o__ 
(_^' No problem is insoluble.

___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] QML arrays and memory leak

2015-05-05 Thread Thomas Tanghus
On Monday 04 May 2015 22:20:17 Kim Foder wrote:
 Hi
 
 For some time I have been battling a memory leak in my pedometer app, after
 a lot of experimentation, I have found the problem to be my use of arrays
 (probably)!
 
 Whenever I receive an acceleration measurement, some statistical
 calculations are made, which results in one float pr. measurement.
 
 As I need the measurements for a certain time for further statistical
 analysis, the results are stored in an array, used as an traveling window
 like this:
 
 accarr.shift();  // the array is pre-initialized with empty elements.
 accarr.push(float);
 
 This works great, but it leaks memory fast, and after some time (between 1 
 2 hours) the OS kills all running apps!
 
 Any ideas how I can solve this?

Do you remove the obsolete values from the array? You don't show that in the 
code snippet.

-- 
Med venlig hilsen / Best regards

Thomas Tanghus
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] QML arrays and memory leak

2015-05-04 Thread Peter Kovacs

Hi Kim,

ohh! Okay!

Have you tried splice instead?
Array.prototype.splice (start, deleteCount [ , item1 [ , item2 [ , … ] ] ] )
I think maybe something like:

accarr.splice(0,1,float)

Looks more neat and it is in the normal javascript canon. Did not find 
the documentation on javascript and qt quick in the rush.

Hope it helps you as a work around.

Peter

On 04.05.2015 23:08, Kim Foder wrote:

Hi Peter


Why use an array and not a vector or an Hash map?

As far as I know those are not supported under javascript, otherwise a vector
would have been my first choice, an Hash map is overkill for my needs, I only
need to add to the end, and always need sequential read.

I am tempted to move the business part to C++, but I'm trying to do as much as
possible in QML (as an exercise).

/Kim


  Am 04.05.2015 22:20 schrieb Kim Foder k...@foder.dk:

Hi

For some time I have been battling a memory leak in my pedometer app,
after a
lot of experimentation, I have found the problem to be my use of arrays
(probably)!

Whenever I receive an acceleration measurement, some statistical
calculations
are made, which results in one float pr. measurement.

As I need the measurements for a certain time for further statistical
analysis, the results are stored in an array, used as an traveling window
like
this:

accarr.shift();  // the array is pre-initialized with empty elements.
accarr.push(float);

This works great, but it leaks memory fast, and after some time (between 1
 2
hours) the OS kills all running apps!

Any ideas how I can solve this?

Thanks.

Kim
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to
devel-unsubscr...@lists.sailfishos.org

___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] QML arrays and memory leak

2015-05-04 Thread Kim Foder
Hi Peter

 Why use an array and not a vector or an Hash map?

As far as I know those are not supported under javascript, otherwise a vector 
would have been my first choice, an Hash map is overkill for my needs, I only 
need to add to the end, and always need sequential read.

I am tempted to move the business part to C++, but I'm trying to do as much as 
possible in QML (as an exercise).

/Kim

 
  Am 04.05.2015 22:20 schrieb Kim Foder k...@foder.dk:
  Hi
  
  For some time I have been battling a memory leak in my pedometer app,
  after a
  lot of experimentation, I have found the problem to be my use of arrays
  (probably)!
  
  Whenever I receive an acceleration measurement, some statistical
  calculations
  are made, which results in one float pr. measurement.
  
  As I need the measurements for a certain time for further statistical
  analysis, the results are stored in an array, used as an traveling window
  like
  this:
  
  accarr.shift();  // the array is pre-initialized with empty elements.
  accarr.push(float);
  
  This works great, but it leaks memory fast, and after some time (between 1
   2
  hours) the OS kills all running apps!
  
  Any ideas how I can solve this?
  
  Thanks.
  
  Kim
  ___
  SailfishOS.org Devel mailing list
  To unsubscribe, please send a mail to
  devel-unsubscr...@lists.sailfishos.org

___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] QML arrays and memory leak

2015-05-04 Thread Peter Kovacs
Why use an array and not a vector or an Hash map?
 Am 04.05.2015 22:20 schrieb Kim Foder k...@foder.dk:

 Hi

 For some time I have been battling a memory leak in my pedometer app,
 after a
 lot of experimentation, I have found the problem to be my use of arrays
 (probably)!

 Whenever I receive an acceleration measurement, some statistical
 calculations
 are made, which results in one float pr. measurement.

 As I need the measurements for a certain time for further statistical
 analysis, the results are stored in an array, used as an traveling window
 like
 this:

 accarr.shift();  // the array is pre-initialized with empty elements.
 accarr.push(float);

 This works great, but it leaks memory fast, and after some time (between 1
  2
 hours) the OS kills all running apps!

 Any ideas how I can solve this?

 Thanks.

 Kim
 ___
 SailfishOS.org Devel mailing list
 To unsubscribe, please send a mail to
 devel-unsubscr...@lists.sailfishos.org

___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org