With reference to the fact that a sieve does not hold all its contents, the phrase a memory, or a mind, like a sieve denotes an extremely poor memory.
However, this phrase has also been used in a different sense: with reference to the opposition between the coarser particles, which are retained by a sieve, and the finer ones, which pass through it, the phrase has been used to contrast what the mind remembers with what it forgets.
These are the earliest occurrences of the phrase a memory, or a mind, like a sieve that I have found, in chronological order:
1-: From The Humble Man. His Depressions, in Judgment and Mercy for Afflicted Souls; or, Meditations, Soliloquies, and Prayers (London: Printed for Longman, Hurst, Rees, and Orme, 1807), by the English author Francis Quarles (1592-1644):
My understanding is darkened with error; my judgment is perverted with partiality; my will is diverted with sensuality; my memory like a sieve, retains the bran, and lets the flower pass.
2-: From Truth’s Triumph; or, A Witness to the two Witnesses; from that unfolded parable of Our Lord and Saviour, Jesus Christ, the High and mighty God, Matthew, chap. 13, verse 30 to 42 (London: Printed by W. Smith, 1823), by the English Muggletonian 1 author Thomas Tomkinson (1631-1710)—the title page indicates that the text was “written in the year of Our Lord God, 1676; Transcribed by the Author, with some Alterations, 1690”:
Our memories here, whilst in mortality, are many times very defective and weak, we are not able to retain what we see and hear, but what goes in at the one ear, goes out at the other, being like unto a sieve, &c.
1 Muggletonian designates a member an antitrinitarian sect founded in England in the mid-17th century by Lodowicke Muggleton (1609-1698) and John Reeve (1608-1658), who claimed to be the two prophetic witnesses referred to in the Book of Revelation, 11:3-6, and maintained that the distinction between the three Persons of the Trinity was merely nominal, and that reason was the creation of the Devil.
3-: From English Exercises for School-Boys to Translate into Latin (London: Printed for J. Nicholson, J. Sprint, A. Bell, S. Burrows; and for M. Walwyn – 1706), by John Garretson, schoolmaster:
Thy mind is a like a Sieve; I will not commit secrets to thy trust; thou hast promised secrecy , but thou forgettest thy promise.
4-: From The Life and Opinions of Tristram Shandy, Gentleman (London: Printed for R. and J. Dodsley, 1760), by the Irish novelist Laurence Sterne (1713-1768):
The cause of obscurity and confusion, in the mind of man, is threefold.
Dull organs, dear Sir, in the first place. Secondly, slight and transient impressions made by objects when the said organs are not dull. And thirdly, a memory like unto a sieve, not able to retain what it has received.
5-: From The Dupe, a Comedy. As it is now Acting at the Theatre-Royal in Drury-Lane, by His Majesty’s Servants (London: Printed for A. Millar, 1764), by the Anglo-Irish novelist and playwright Frances Sheridan (née Chamberlaine – 1724-1766):
—as published in The Plays of Frances Sheridan (Newark: University of Delaware Press – London and Toronto: Associated University Presses – 1984), edited by Robert Hogan and Jerry C. Beasley:
Mrs. Etherdown: Get you gone, we have no time to lose.
Sharply: There’s a small point to be adjusted first between you and me.
Mrs. Etherdown: What’s that?
Sharply [Makes signs of counting money on his hand.]: I budge not a foot without it.
Mrs. Etherdown: Oh!—Come with me into my closet.—I had quite forgot.
Sharply: Your memory is prodigiously like a sieve;
Your interest it preserves, like weighty grains,
But promises are chaff, it ne’er retains.
6-: From a letter by Thomas Tyers (1726-1787), first published in The Public Advertiser (London, England), as quoted in The Genuine Works of William Hogarth; illustrated with Biographical Anecdotes, a Chronological Catalogue, and Commentary (London: Printed for Longman, Hurst, Rees, and Orme, 1808), by John Nichols (1745-1826) and George Stevens (1736-1800)—Tyers defined memory as:
a faculty which, like the sieve of the Danaids 2, is apt to lose as much as it receives.
2 In Greek mythology, the Danaids were the fifty daughters of Danaus, king of Argos, who were compelled to marry the sons of his brother Aegyptus but murdered their husbands on the wedding night, except for one, Hypermnestra, who helped her husband to escape. The remaining Danaids were condemned eternally to pour water into bottomless or sieve-like vessels.
7-: From Discourses upon the great festivals, as stated in the calendar and rubricks of the Church of England (Manchester: Russell and Allen, 1812), by Thomas Taylor:
What a world of iniquity is there to destroy in man’s fallen soul! There is a carnal mind, like a rock of adamant; here is unbelief like a gate of brass; here is self will like an iron pillar; here is a poluted [sic] conscience, like an incurable leprosy; here sinful affections like the swarms of frogs and lice which corrupted all the land of Egypt; here is a corrupt memory, like a cage of unclean birds; or like a sieve which lets the precious liquor run out, but retains the dregs.