Ajax polling by using recursion - Memory ramp up? Stack overflows?

Discussion in 'Javascript' started by Brian Takita, Oct 17, 2007.

  1. Brian Takita

    Brian Takita Guest

    Hello, we are implementing a function that uses recursion to poll a
    server. This implementation seems like it would cause a memory ramp up
    and possibly a stack overflow. Am I correct? Is there anyway to
    accomplish polling without this issue?
    function poll() {
    $.get('/message_queue/' + gaming_session.guid,
    function(command_string) {
    var messages = JSON.parse(command_string);
    for (var i = 0; i < messages.length; i++) {
    Model.execute_server_commands(messages);
    }
    poll();
    });
    }
    poll();
     
    Brian Takita, Oct 17, 2007
    #1
    1. Advertising

  2. Brian Takita

    David Mark Guest

    On Oct 16, 10:37 pm, Brian Takita <> wrote:
    > Hello, we are implementing a function that uses recursion to poll a
    > server. This implementation seems like it would cause a memory ramp up
    > and possibly a stack overflow. Am I correct? Is there anyway to
    > accomplish polling without this issue?


    You are incorrect. Unless you are using a synchronous request, this
    is not recursion. I don't think it makes sense to use an anonymous
    function for the callback though. Why not declare the callback
    function outside of poll and pass a reference to the get method?

    > function poll() {
    > $.get('/message_queue/' + gaming_session.guid,
    > function(command_string) {
    > var messages = JSON.parse(command_string);
    > for (var i = 0; i < messages.length; i++) {
    > Model.execute_server_commands(messages);
    > }
    > poll();
    > });
    > }
    > poll();
     
    David Mark, Oct 17, 2007
    #2
    1. Advertising

  3. Brian Takita

    Brian Takita Guest

    On Oct 16, 9:46 pm, David Mark <> wrote:
    > On Oct 16, 10:37 pm, Brian Takita <> wrote:
    >
    > > Hello, we are implementing a function that uses recursion to poll a
    > > server. This implementation seems like it would cause a memory ramp up
    > > and possibly a stack overflow. Am I correct? Is there anyway to
    > > accomplish polling without this issue?

    >
    > You are incorrect. Unless you are using a synchronous request, this
    > is not recursion. I don't think it makes sense to use an anonymous
    > function for the callback though. Why not declare the callback
    > function outside of poll and pass a reference to the get method?
    >
    > > function poll() {
    > > $.get('/message_queue/' + gaming_session.guid,
    > > function(command_string) {
    > > var messages = JSON.parse(command_string);
    > > for (var i = 0; i < messages.length; i++) {
    > > Model.execute_server_commands(messages);
    > > }
    > > poll();
    > > });
    > > }
    > > poll();


    So does the callback invocation create a new stack frame?
     
    Brian Takita, Oct 17, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tiflis

    ramp generator

    tiflis, Feb 16, 2007, in forum: VHDL
    Replies:
    1
    Views:
    801
    Mike Treseler
    Feb 16, 2007
  2. Daz

    Stack overflows

    Daz, Jun 20, 2006, in forum: C++
    Replies:
    6
    Views:
    412
    Steve Pope
    Jun 22, 2006
  3. chucky
    Replies:
    4
    Views:
    617
    Mark Space
    Aug 5, 2007
  4. RicardoNeves

    Internal Prak Ramp Module

    RicardoNeves, Nov 22, 2010, in forum: VHDL
    Replies:
    0
    Views:
    610
    RicardoNeves
    Nov 22, 2010
  5. Replies:
    1
    Views:
    125
Loading...

Share This Page