public void Dispose() { for (var i = 0; i < Pages.Count; i++) { BufferSource.Return(Pages[i]); } Pages.Clear(); }
public void Dispose() { var pages = Pages; var count = pages.Count; for (var i = 0; i < count; i++) { BufferSource.Return(pages[i]); } pages.Clear(); }
private char[] NewPage() { char[] page = null; try { page = BufferSource.Rent(PageSize); Pages.Add(page); } catch when(page != null) { BufferSource.Return(page); throw; } return(page); }
/// <summary> /// Return all but one of the pages to the <see cref="ICharBufferSource"/>. /// This way if someone writes a large chunk of content, we can return those buffers and avoid holding them /// for extended durations. /// </summary> public void Clear() { for (var i = Pages.Count - 1; i > 0; i--) { var page = Pages[i]; try { Pages.RemoveAt(i); } finally { BufferSource.Return(page); } } _charIndex = 0; CurrentPage = Pages.Count > 0 ? Pages[0] : null; }