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 8624381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:31:02+00:00 2026-06-12T07:31:02+00:00

I have a text editing program that hands out cursors to other parts of

  • 0

I have a text editing program that hands out cursors to other parts of the program that require it. The cursor consists of a two part list, [start, end], which needs to be updated every time text is inserted/removed (the start/end index gets moved forward or backwards).

When the cursor is no longer used, I want to stop updating it, since there are many and they are time consuming to update. By not in use, I mean that the object that requested it no longer references it – it no longer cares about it. (For example: it has a list of cursors to all search results for the word ‘bob’, and a new search was made for the word ‘fred’, so now it replaces its result list with a new list of new cursors… the old list and its cursors are no longer used.)

I can require that any object using the cursor calls a .finished() method when it no longer needs it. But it would be easier if I could detect when it is no longer being referenced by anything outside of the editor. How do I check this in python (I know the garbage cleanup maintains a list, and deletes it when no longer referenced)?

  • 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-06-12T07:31:03+00:00Added an answer on June 12, 2026 at 7:31 am

    Use a weak reference from the weakref module to hold your cursor reference.

    When the referent of a weak reference no longer has any strong (normal) references to it, the weakref will resolve to None.

    >>> import weakref
    >>> class Cursor: pass
    ... 
    >>> _ = None # suppress special _ variable
    >>> a = Cursor()
    >>> r = weakref.ref(a)
    >>> print r()
    <__main__.Cursor instance at 0x1004a2bd8>
    >>> del a
    >>> print r()
    None
    

    You can put all those weakrefs in a collection (or use WeakKeyDictionary, WeakValueDictionary, or WeakSet) to keep track of the various cursors you have to update.

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

Sidebar

Related Questions

I have a text editing program that saves it's output into a PDF file.
Does anyone know any cool text editing program for easy code translation? I have
I have text within a paragraph tag that that fits snug on the bottom
I have text I am displaying in SIlverlight that is coming from a CMS
I have text file with some stuff that i would like to put into
I have text stored in SQL as HTML. I'm not guaranteed that this data
I have a file with lots of text editing using NotePad++. for example <span
obj-c question. I have text that I parse that contains CDDATA (html amp chars
I have an application with a view that has text fields from the top
I have text fields inside a custom view inside an NSOutlineView . Editing one

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.