EWSoftware / PDI

A Personal Data Interchange (PDI) library that implements the vCard (RFC 2426), vCalendar, and iCalendar (RFC 2445) specifications including recurrence pattern generation
Microsoft Public License
64 stars 26 forks source link

OutOfMemory when recurrence is monthly on a specific weekday #17

Closed adrha closed 3 years ago

adrha commented 3 years ago

Hey

I'm getting an OutOfMemory-Exception, when i'm trying to calculate the recurrence of the following event: Start-Date: 11. June 2011 Frequency: monthly ByDay: TH

Basically a recurrence every month on thursday.

It works, when the frequency is set to weekly - but not on monthly.

Is this a known issue?

Thank you!

EWSoftware commented 3 years ago

Without an end date or maximum number of occurrences, recurrences will go on forever (well, 12/31/9999). In this case, it looks like it isn't handling it correctly and isn't ending. Setting an end date or maximum number of occurrences will work around it for now. In general, it's always best to set an end date or maximum number of occurrences or it's just wasted time and space computing hundreds of thousands of unwanted dates.

adrha commented 3 years ago

Unfortunately this is not the error. I'm always setting the EndDate to today+14days. So a monthly recurrence since 2011 should not exceed 108 items when calculating.

When i'm setting the recurrence to weekly, it calculates perfectly fine and fast and returns me the list of hundreds of items. Even with a weekly recurrence, starting in 1990 i'm getting the result fast and without performance-issues. (1560 items).

adrha commented 3 years ago

Hey i reviewed the code and figured out, that i'm just filtering the events by an EndDate, after the recurrences have been processed. So as this recurrence had no specified end-date, it might have calculated forever (till 9999) as you mentioned before. After adding a manual end-date in the code, it works as expected! Thank you!

EWSoftware commented 3 years ago

Thanks for the update. I do need to look into why it didn't stop though given the specific case so I've reopened this issue.

EWSoftware commented 3 years ago

I fixed the underlying issue and published an update.