New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recommended 'my sub' example in perlsub leaks memory #15470
Comments
From @maukeCreated by @maukeperldoc perlsub: | To use a lexical subroutine from inside the subroutine itself, you must This example leaks memory, just like my $baz; ($baz keeps the sub alive, the sub keeps $baz alive). It would be really good if recursive lexical subs could be made to not leak Alternatively, this example should be removed from the documentation and Perl Info
|
From @cpansproutOn Sat Jul 23 15:11:40 2016, mauke- wrote:
It cannot be fixed in general, because if you have two subs referencing each other in their pads-- my sub foo; --then you cannot know which pointer to weaken, since you cannot tell which sub will be referenced by user code last. It might be possible to add a special case to break the reference loop of a self-referential sub. But there is no standard for storing a weak pointer in a pad (except the format hack). It’s not clear where to store the flag marking the pointer as weak. Now, there is a hack for storing weak pointers to formats in pads (which are stored there solely for the sake of fixing up CvOUTSIDE pointers if they are defined within predeclared subs) consists of storing a weak RV which points to the format. If we apply that to lexical subs, then padcv will have to have an extra special case to check for an RV. Is it worth the added complexity for something that is only a partial fix? If we need to educate users anyway, do we need a special case?
Or replaced with a state sub example. state subs will also leak, but no more than sub AUTOLOAD { our $AUTOLOAD }
Good idea. -- Father Chrysostomos |
The RT System itself - Status changed from 'new' to 'open' |
From zefram@fysh.orgThe documentation was changed in the suggested way in commit -zefram |
@mauke - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release yesterday of Perl 5.28.0, this and 185 other issues have been Perl 5.28.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#128708 (status was 'resolved')
Searchable as RT128708$
The text was updated successfully, but these errors were encountered: