Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4243214
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:32:54+00:00 2026-05-21T03:32:54+00:00

I was troubleshooting an application today at work that runs periodically to handle some

  • 0

I was troubleshooting an application today at work that runs periodically to handle some data processing needs, it often runs just fine but sometimes the application will crash and someone will have to manually restart it.

After looking at the source and some debugging it seems the core of the program relies on a recursive function that is removing rows from a DataTable and then stopping once the DataTable no longer has any rows remaining.

Here is the code:

Public Sub ProcessData(ByRef dtTable As DataTable)
  Dim DataView1 As New DataView()
  Dim UID As String = ""
  Dim dtUID As New DataTable

  dtUID = dtTable.Clone()
  UID = dtTable.Rows(0)("UID")    

  DataView1 = dtTable.DefaultView

  Dim expression As String = "UID ='" & UID & "'"
  DataView1.RowFilter = expression

  For n As Integer = 0 To DataView1.Count - 1
      dtUID.ImportRow(DataView1.Item(n).Row)
  Next

  Dim foundRows() As DataRow
  foundRows = dtTable.Select(expression)

  For n As Integer = 0 To foundRows.GetUpperBound(0)
      dtTable.Rows.Remove(foundRows(n))
  Next

  For n As Integer = 0 To dtUID.Rows.Count - 1
      ProcessRecord(dtUID, n)
  Next

  If dtTable.Rows.Count > 0 Then
      ProcessData(dtTable)
  End If
End Sub

ProcessRecord() is a function that applies all the business logic to the record and also does a write to a database. The unhandled stack overFlow exception happens at:

For n As Integer = 0 To DataView1.Count - 1

In the real world this function would be fed a DataTable with around 100,000 records in it. In testing it, it will run through about 40,000-65,000 pretty consistently after many trial runs before it has the stack overflow. The code that creates the DataTable and ProcessRecord() flag records that have already been processed, so if you’re working through a 100,000 record large data set then subsequent calls to this method after a crash will be passed a smaller DataTable (35,000-60,000 records.) Interestingly the stack overflow will happen more and more often with smaller DataTables, I can consistently get through 40k-65k of a 100k DataTable but cannot consistently get through 15k of a 15k DataTable without a crash (eventually it will complete all records, with multiple crashes over the last few thousand.)

Once I saw what the problem was I basically scrapped most of this code and used an implementation I’ve used for similar tasks in the past. But I really wanted to understand exactly why this code was causing this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:32:55+00:00Added an answer on May 21, 2026 at 3:32 am

    The problem is simply that it is a recursive function.

    Each function invocation uses stack space to store its parameters and local variables, and stack space is limited.

    There’s no reason that this particular operation should be recursive. In fact, when the maximum number of recursions cannot be estimated or limited easily, it’s a bad idea to use a recursive solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems
I've been troubleshooting a major performance issue in a SL4 application that utilizes the
As the author of a C# application, I found that troubleshooting issues reported by
I'm having some problems with deploying my application and while troubleshooting, I came across
I'm creating an universal application and my CCMenu appears just fine on both iPhone,
I am trying to work out some memory leak issues in an application, and
Intro: I have written some short excel macros (tested, they work fine) and want
I'm troubleshooting a problem with a Visual Fox Pro application (built with the Visual
I have tried troubleshooting this problem and just ended up with nothing, I hope
first of all, my main question: What are some good troubleshooting techniques when you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.